Hi,
I'm setting up a project to use Auditing and I've run into an issue with XML deserialization.
I've written the Auditors WriteXml/ReadXml methods based on this thread - https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=13609 - and they look like this:
public override void WriteXml(System.Xml.XmlWriter writer, SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect aspects,
System.Collections.Generic.Dictionary<System.Guid, SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore> processedObjectIDs)
{
foreach(EntityClasses.AuditEmployeeEntity auditInfoEntity in _auditInfoEntities)
{
auditInfoEntity.WriteXml(writer, SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect.Compact |
SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect.DatesInXmlDataType |
SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect.MLTextInCDataBlocks);
}
}
public override void ReadXml(System.Xml.XmlNode auditorNode)
{
System.Xml.XmlReader reader = new System.Xml.XmlNodeReader(auditorNode);
this.ReadXml(reader);
}
public override void ReadXml(System.Xml.XmlReader reader)
{
reader.MoveToContent();
string startElementName = reader.LocalName;
while (reader.Read() && !((reader.LocalName == startElementName) && (reader.NodeType == System.Xml.XmlNodeType.EndElement)))
{
EntityClasses.AuditEmployeeEntity toDeserialize = new EntityClasses.AuditEmployeeEntity();
toDeserialize.ReadXml(reader);
_auditInfoEntities.Add(toDeserialize);
}
}
Now in my main application I have something like this...
Dim employeeXmlString As String = String.Empty
employeeGeneralEntity.WriteXml(SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect.Compact Or _
SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect.DatesInXmlDataType Or _
SD.LLBLGen.Pro.ORMSupportClasses.XmlFormatAspect.MLTextInCDataBlocks, employeeXmlString)
Session(StringConstantSession.ProfilePackageKey) = employeeXmlString
[...]
employeeGeneralEntity = New EntityClasses.EmpGeneralEntity
Dim profilePackage As String = Session(StringConstantSession.ProfilePackageKey).ToString()
employeeGeneralEntity.ReadXml(profilePackage)
The last line - ReadXml - throws this error
System.NullReferenceException was caught
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=SD.LLBLGen.Pro.ORMSupportClasses
StackTrace:
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Dictionary2 processedObjectIDs, List
1 nodeEntityReferences) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.2\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityBase2.cs:line 1452
at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore1.ReadXml(XmlNode node, XmlFormatAspect format) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.2\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityCore.cs:line 3061
at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore
1.ReadXml(String xmlData) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.2\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityCore.cs:line 3035
at [...].Page_Load(Object sender, EventArgs e)
InnerException:
The XML being deserialized looks like this:
<EmpGeneralEntity Id="1">
<Fields>
[...]
</Fields>
<EntityState>Fetched</EntityState>
<IsNew>false</IsNew>
<IsDirty>true</IsDirty>
<Auditor>
<AuditEmployeeEntity Id="">
<Fields>
[...]
</Fields>
<EntityState>New</EntityState>
<IsNew>true</IsNew>
<IsDirty>true</IsDirty>
<ObjectID>7b781eb7-ca2b-4e6c-9f82-92a24eeaee6b</ObjectID>
</AuditEmployeeEntity>
</Auditor>
<ObjectID>83659f7e-c574-49e3-885e-8a9ac19f8dba</ObjectID>
</EmpGeneralEntity>
I'm using v4.2
The Auditors are added by overriding the CreateAuditor method with templates.
This deserialization worked before adding Auditing.
Any help would be appreciated.