In the following class


In the GetReferencesTo method, the 'item' can become null in the first foreach. DO crashes with 'null reference' exception when trying to access the 'item.Entity'.

Regards Paul Sinnema Diartis AG

    /// <inheritdoc/>
    public override IEnumerable<ReferenceInfo> GetReferencesTo(Entity target, AssociationInfo association)
      switch (association.Multiplicity) {
        case Multiplicity.ManyToOne:
        case Multiplicity.ZeroToOne:
        case Multiplicity.ZeroToMany:
        case Multiplicity.ManyToMany:
          var list = new List<ReferenceInfo>();
          var state = disconnectedState.GetEntityState(target.Key);
          foreach (var reference in state.GetReferences(association.OwnerField)) {
            var item = FetchEntityState(reference.Key);
            list.Add(new ReferenceInfo(item.Entity, target, association));
          return list;
        case Multiplicity.OneToOne:
        case Multiplicity.OneToMany:
          var key = target.GetReferenceKey(association.Reversed.OwnerField);
          if (key!=null)
            return EnumerableUtils.One(new ReferenceInfo(FetchEntityState(key).Entity, target, association));
      throw new ArgumentException("association.Multiplicity");

Updated at 30.07.2010 11:38:36

Just to illustrate what's going wrong.

Test 'Diartis.KLIB.KLIBUnitTests.VMMaintenanceStateMachineTest.PersonTest' failed: System.NullReferenceException : Object reference not set to an instance of an object.
  at Xtensive.Storage.Disconnected.DisconnectedSessionHandler.GetReferencesTo(Entity target, AssociationInfo association)
  at Xtensive.Storage.ReferenceFinder.GetReferencesTo(Entity target, AssociationInfo association)
  at Xtensive.Storage.ReferentialIntegrity.RemovalProcessor.ProcessItems(IList`1 entities)
  at Xtensive.Storage.ReferentialIntegrity.RemovalProcessor.Remove(IEnumerable`1 entities)
  at Xtensive.Storage.Entity.Remove()
  AbstractEntity.cs(570,0): at Diartis.KLIB.Model.AbstractEntity.OnDelete()
  Generated\Contact.Generated.cs(923,0): at Diartis.KLIB.Model.Contact.OnDelete()
  Generated\Person.Generated.cs(2109,0): at Diartis.KLIB.Model.Person.OnDelete()
  AbstractEntity.cs(556,0): at Diartis.KLIB.Model.AbstractEntity.Delete()
  VMEntity.cs(522,0): at Diartis.KLIB.KLIBViewModel.VMEntity.Delete()
  StateMachines\VMMaintenanceStateMachine.cs(370,0): at Diartis.KLIB.KLIBViewModel.StateMachines.VMMaintenanceStateMachine`1.Cancel()
  VMMaintenanceStateMachineTest.cs(95,0): at Diartis.KLIB.KLIBUnitTests.VMMaintenanceStateMachineTest.PersonTest()

Updated at 31.07.2010 23:57:27

Hi Alex,

It's right here:

var item = FetchEntityState(reference.Key);
            list.Add(new ReferenceInfo(item.Entity, target, association));

I've debugged the code into the FetchEntityState(). That's where it becomes null.

Regards Paul

Updated at 07.08.2010 10:54:33

What's the status of this one?

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Jul 30 '10 at 10:41

Paul%20Sinnema's gravatar image

Paul Sinnema

edited Sep 03 '10 at 15:47

Alex%20Yakunin's gravatar image

Alex Yakunin

Could you try to reproduce it with our .PDBs to get info about line number?

(Jul 30 '10 at 10:41) Alex Yakunin Alex%20Yakunin's gravatar image

No any updates yet, but I'll contact you about this soon - likely, I'll need more details.

(Jul 30 '10 at 10:41) Alex Yakunin Alex%20Yakunin's gravatar image

Up. Will be investigated shortly.

(Sep 03 '10 at 15:49) Alex Yakunin Alex%20Yakunin's gravatar image

Just fixed this.

(Sep 24 '10 at 08:11) Alex Yakunin Alex%20Yakunin's gravatar image

One Answer:

Issue created: http://code.google.com/p/dataobjectsdotnet/issues/detail?id=794

answered Sep 03 '10 at 16:33

Alex%20Yakunin's gravatar image

Alex Yakunin

Just fixed.

(Sep 24 '10 at 08:12) Alex Yakunin Alex%20Yakunin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA