Hello,

We are migrating our application to DataObjects 4.0.5 and I've a problem with abstract classes: I'm getting NullReference exceptions when trying to use an object with it's abstract base class.

Am I doing something wrong?

Persistent classes :

[HierarchyRoot]
  public abstract class Trigger : Entity
  {
    [Field, Key]
    public long Id { get; private set; }

    public abstract string ToText();
  }

  public class SimpleTrigger : Trigger
  {
    [Field]
    public TimeSpan Delay { get; set; }

    public override string ToText()
    {
      return Delay.ToString();
    }
  }

Code (without domain build)

using (Session.Open(domain))
      using(TransactionScope transactionScope = Transaction.Open())
      {
        new SimpleTrigger { Delay = TimeSpan.FromSeconds(1.0) };
        transactionScope.Complete();
      }

      using (Session.Open(domain))
      using (TransactionScope transactionScope = Transaction.Open())
      {
        SimpleTrigger myTrigger = Query<SimpleTrigger>.All.First<SimpleTrigger>();
        Console.WriteLine(myTrigger.ToText()); // working as expected
        transactionScope.Complete();
      }

      using (Session.Open(domain))
      using (TransactionScope transactionScope = Transaction.Open())
      {
        Trigger myTrigger = Query<Trigger>.All.First<Trigger>();
        Console.WriteLine(myTrigger.ToText()); // NullReferenceException
        transactionScope.Complete();
      }

Exception below :

System.NullReferenceException was unhandled
  Message="La référence d'objet n'est pas définie à une instance d'un objet."
  Source="Xtensive.Core"
  StackTrace:
       à Xtensive.Core.Tuples.Tuple.GetValueOrDefault[T](Int32 fieldIndex)
       à Xtensive.Storage.Internals.DefaultFieldAccessor`1.GetValue(Persistent obj, FieldInfo field)
       à Xtensive.Storage.Persistent.GetFieldValue[T](FieldInfo field)
       à Xtensive.Storage.Persistent.GetFieldValue[T](String fieldName)
       à TestDO4.SimpleTrigger.get_Delay()
       à TestDO4.Program.Main(String[] args) dans Visual Studio 2008\Projects\TestDO4\TestDO4\Program.cs:ligne 35
       à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Regards,


Updated at 11.09.2009 13:37:01

After some more investigation, this problem occurs also with virtual methods.

Class not abstract, but with an overridden virtual method.

[HierarchyRoot]
  public class Trigger : Entity
  {
    [Field, Key]
    public long Id { get; private set; }

    public virtual string ToText()
    {
      return null;
    }
  }

  public class SimpleTrigger : Trigger
  {
    [Field]
    public TimeSpan Delay { get; set; }

    public override string ToText()
    {
      return Delay.ToString();
    }
  }

When calling Trigger.ToText() I get the same null reference exception on Delay.

Regards,


Updated at 11.09.2009 14:27:38

Thanks for your really fast answer: I'll use your work around, it is much better than mine.

Regards,

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

asked Sep 11 '09 at 13:28

olorin's gravatar image

olorin
356838489

The problem looks really strange. We'll try to isolate it during this weekend.

(Sep 11 '09 at 13:28) Alex Yakunin Alex%20Yakunin's gravatar image

Already fixed in 12502 revision.

See nightly build or wait for 4.0.6.

P.S. In case you can't wait or use nightly build there is a workaround: you should mark these fields with [Field(LazyLoad = true)] attribute.

(Sep 11 '09 at 13:28) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

I can add that all data loading stuff now is anyway refactored, since we're implementing preloading in DO4.

So likely similar issues will be studied closer... But new ones might appear as well :( As you see, our test suite isn't ideal. I really surprised such a bug could exists there for such a long period.

answered Sep 12 '09 at 04:14

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

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