Bug in ADO.NET ObjectSpaces?

Yesterday (well, actually it was today, because it was from 23.30 till 1.30), I was working on my lunch presentation for the Developer Days 2004. Earlier that day I ran into a problem with the ObjectSpace class, trying to persist a new object. It was really a simple piece of code when I reduced the problem to:

SqlConnection conn = new SqlConnection(“DATA SOURCE=.;INTEGRATED SECURITY=SSPI“);
ObjectSpace os = new ObjectSpace(“MyMappingSchema.xml“, conn);
Posting p = new Posting();
p.Title = “Some title“;
p.Body = “This is the body“;
os.StartTracking(p, InitialState.Inserted);

What I kept getting was a NullReferenceException on the last call. I can assure you that both the os variable and the p variable had non-null values. It took me till half past one in the night to find the cause:

<osd:ExtendedObjectSchema Name=”BlogObjectSchema” xmlns:osd=”http://schemas.microsoft.com/data/2002/09/20/persistenceschema“>
    <osd:Class Name=”Posting”>
      <osd:Member Name=”Title” />
      <osd:Member Name=”Id” Key=”true” KeyType=”AutoIncrement” />
      <osd:Member Name=”Body” />

I’ve bolded the offending line. When I swapped that line with the Title member, everything worked like a charm. I think this is a bug in ObjectSpaces. Nowhere is it stated that the order of declarations is significant; at least, not that I could find.

Does anybody have any experience with this feature/bug?

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s