NullReference when using Entity

Posts   
 
    
nb@zeag
User
Posts: 3
Joined: 26-Nov-2007
# Posted on: 26-Nov-2007 14:59:12   

Hi, I have been looking at the demo version 2.5 and using VS2005. I am trying to follow the Adapter tutorials whilst using my own database tables from SQL 2005. The runtime SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll lib version is 2.5.7.1119 I have a windows console with the following code:

       static void Main(string[] args)
        {
            RelationPredicateBucket filter = new RelationPredicateBucket();
            EntityCollection<SpmcustomersEntity> customers = new EntityCollection<SpmcustomersEntity>();

            // [C#]
            StreamWriter writer = new StreamWriter("customer.XML");
            string customerXml = String.Empty;
            customers.WriteXml(out customerXml);
            writer.Write(customerXml);
            writer.Close();

            // now read it back
            StreamReader reader = new StreamReader("customer.XML");
            string xmlFromFile = reader.ReadToEnd();
            reader.Close();
            SpmcustomersEntity customerFromXml = new SpmcustomersEntity();
            customerFromXml.ReadXml(xmlFromFile);
        }

The code causes an exception when trying to read back the xml file with the following exception:

System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Dictionary2 processedObjectIDs, List1 nodeEntityReferences) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlNode node, XmlFormatAspect format) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(String xmlData) at ORMapperConsole.Program.Main(String[] args) in C:\Documents and Settings\Neil\My Documents\LLBLGen Pro Projects\ORMapperConsole\Program.cs:line 123 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

Any idea what I have done wrong? I have attached the XML output.

Thank you in advance, Neil.

Attachments
Filename File size Added on Approval
customer.XML 753 26-Nov-2007 14:59.53 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 26-Nov-2007 15:54:02   

You have a type converter in the SpmcustomersEntity entity? Or is it a normal entity, with normal types and no type converter?

The code suggests the collection is empty, we'll have a look.

Frans Bouma | Lead developer LLBLGen Pro
nb@zeag
User
Posts: 3
Joined: 26-Nov-2007
# Posted on: 26-Nov-2007 16:45:48   

Hi,

I hadn't specified any type convertors when building the LLBLGen project. All fields should be normal DB types, either Int, Varchar, Float, Money or DateTime with no type convertors specified.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 26-Nov-2007 17:28:22   

I see your mistake: you serialize a COLLECTION but you deserialize the xml in an ENTITY simple_smile You can of course only deserialize collection xml into a new collection.

Frans Bouma | Lead developer LLBLGen Pro
nb@zeag
User
Posts: 3
Joined: 26-Nov-2007
# Posted on: 26-Nov-2007 17:49:25   

Thank you for sorting that out.

Sorry for troubling you with such a stupid question. flushed