none
File EntityEntry.cs: Exception: NullReferenceEception: _cache is null RRS feed

  • Question

  • I found a strange behaviour of the Entity Framework. Unfortunatly the exception occures in a quite complicated application working on confiddential data only. I have not been able to create a simplified enviroment or artificial data reproducing the error.
    Therefore I'm only able to describe the general procedure producing the exception:
    Enviroment:
    The application works with Entity Framwork 4.1 Update 1. The underlaying database is hosted by a Sql-Server 2008 Standard Editon instance. The exception is traced by enabling the 'Enable .NET Framework source stepping' option in the debugging section of the VS options.
    Process:
    The application loads several loosly coupled objects trees into one ObjectContext. The application also detaches individual object trees on user request to replace them by another set of data. One of these object trees is called vehicleFamilyPools.
    To produce the error I have to:
    1.) Load vehicleFamilyPool dataset A into context.
    2.) Detach dataset A and load vehicleFamilyPool dataset B into context.
    3.) Detach dataset B and load vehicleFamilyPool dataset A into context.
    The exception shown below is thrown when the root element of dataset A is loaded in step 3.
    While one can choose dataset B abitrary, only very few vehicleFamilyPool datasets produce the error in the role of dataset A. I have not been able to identify any structural differences between the datasets that cause the error and the ones which do not  cause the error.
    As far as I see in debug-mode, a null reference should also trigger the Debug.Assert. I would be gratefull for any hint, what might cause the problem.

    File EntityEntry.cs: Exception: NullReferenceEception: _cache is null

            internal void FixupReferencesByForeignKeys(bool replaceAddedRefs) 
            {
                Debug.Assert(_cache != null"Attempt to fixup detached entity entry"); 
                _cache.TransactionManager.BeginGraphUpdate();
    Wednesday, October 5, 2011 2:39 PM

All replies

  • Here is the call stack:

    System.Data.Objects.EntityEntry.FixupReferencesByForeignKeys(bool replaceAddedRefs) Line 3260

    System.Data.Objects.ObjectStateManager.FixupReferencesByForeignKeys(System.Data.Objects.EntityEntry newEntry, bool replaceAddedRefs) Line 466

    System.Data.Objects.ObjectStateManager.PromoteKeyEntry(System.Data.Objects.EntityEntry keyEntry, System.Data.Objects.Internal.IEntityWrapper wrappedEntity, System.Data.IExtendedDataRecord shadowValues, bool replacingEntry, bool setIsLoaded, bool keyEntryInitialized, string argumentName) Line 718

    System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly<Prosim.Operation.Database.VehicleFamilyPools>(System.Func<System.Data.Common.Internal.Materialization.Shaper,System.Data.Objects.Internal.IEntityWrapper> constructEntityDelegate, System.Data.EntityKey entityKey, System.Data.Metadata.Edm.EntitySet entitySet) Line 225

    [Lightweight Function]

    System.Data.Common.Internal.Materialization.Coordinator<Prosim.Operation.Database.VehicleFamilyPools>.ReadNextElement(System.Data.Common.Internal.Materialization.Shaper shaper) Line 274

    System.Data.Common.Internal.Materialization.Shaper<Prosim.Operation.Database.VehicleFamilyPools>.RowNestedResultEnumerator.MoveNext() Line 1284

    System.Data.Common.Internal.Materialization.Shaper<System.__Canon>.ObjectQueryNestedEnumerator.TryReadToNextElement() Line 1430

    System.Data.Common.Internal.Materialization.Shaper<System.__Canon>.ObjectQueryNestedEnumerator.MoveNext() Line 1360 + 0x8 bytes C#

    System.Linq.Enumerable.FirstOrDefault<Prosim.Operation.Database.VehicleFamilyPools>(System.Collections.Generic.IEnumerable<Prosim.Operation.Database.VehicleFamilyPools> source)

    System.Data.Objects.CompiledQuery.ExecuteQuery<Prosim.Operation.Database.VehicleFamilyPools>(System.Data.Objects.ObjectContext context, object[] parameterValues) Line 576

    System.Data.Objects.CompiledQuery.Invoke<Prosim.Operation.Database.FeoEntities,Prosim.Operation.Common.Poco.Domains.IDomainUniqueShape,Prosim.Operation.Database.VehicleFamilyPools>(Prosim.Operation.Database.FeoEntities arg0, Prosim.Operation.Common.Poco.Domains.IDomainUniqueShape arg1) Line 397

    Prosim.Operation.Businesslogic.Database.Domains.VehicleFamilyPools.Read(Prosim.Operation.Common.Poco.Domains.IDomainUniqueShape shape, Prosim.Operation.Database.FeoEntities context) Line 216

    Prosim.Operation.Businesslogic.Domains.DomainLoaderBase<Prosim.Operation.Database.VehicleFamilyPools>.Load<Prosim.Operation.Businesslogic.Database.Domains.VehicleFamilyPools>(Prosim.Operation.Common.Poco.Domains.IDomainUniqueShape key, string errorMessage) Line 108

    Prosim.Operation.Businesslogic.VehicleFamilyPoolManager.VehicleFamilyPoolLoader.Load(Prosim.Operation.Common.Poco.Domains.IDomainUniqueShape key) Line 146

    Prosim.Operation.Businesslogic.Domains.DomainLoadingProcessor.LoadDomain<Prosim.Operation.Database.VehicleFamilyPools>(Prosim.Operation.Businesslogic.Domains.DomainLoaderBase<Prosim.Operation.Database.VehicleFamilyPools> loader, Prosim.Operation.Common.Poco.Domains.IDomainUniqueShape newKey, Prosim.Operation.Businesslogic.Database.IDomainAndKeyAndSchedule<Prosim.Operation.Database.VehicleFamilyPools> currentData, bool changeCurrent) Line 484

    -- stack trace is cut here to get the text into the forums textbox

    Wednesday, October 5, 2011 2:40 PM