I use the following helper functions to XML serialize/de-serialize entity objects.
Private Shared Function VersionFileName(ByVal entity As IEntity2, ByVal versionName As String) As String
Return String.Format("{0}.{1}", versionName, entity.ObjectID.ToString)
End Function
Public Shared Sub SaveEtityVersion(ByVal entity As IEntity2, ByVal versionName As String)
Dim writer As System.io.StreamWriter
writer = New System.io.StreamWriter(VersionFileName(entity, versionName))
Dim cloneXML As String = String.Empty
entity.WriteXml(cloneXML)
writer.Write(cloneXML)
writer.Close()
End Sub
Public Shared Sub RollbackEtityVersion(ByVal entity As IEntity2, ByVal versionName As String)
Dim reader As System.io.StreamReader
reader = New System.IO.StreamReader(VersionFileName(entity, versionName))
Dim xmlFromFile As String = reader.ReadToEnd()
reader.Close()
'preserver ParentObject for each child
entity.ReadXml(xmlFromFile)
End Sub
When my entity's related collection is empty all is working OK; but when the related GLMoneyWithdrawalDetailItems collection has any item in it the RollbackEtityVersion function would fail with the follwing error:
Module: ReflectPropertyDescriptor
Routine: SetValue
Message: • Object type cannot be converted to target type.
Stack Trace:
• at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Hashtable processedObjectIDs, ArrayList nodeEntityReferences)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2.Xml2EntityCollection(XmlNode node, Hashtable processedObjectIDs, ArrayList nodeEntityReferences)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Hashtable processedObjectIDs, ArrayList nodeEntityReferences)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlNode node)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(String xmlData)
at JCL.LLBLHelper.RollbackEtityVersion(IEntity2 entity, String versionName) in D:\Projects\LLBL\JCL\JCL\Helpers.vb:line 86
at JCL.Windows.DataForm.CancelEdit() in D:\Projects\LLBL\JCL\JCL.Windows\DataForm.vb:line 2616
The strange thing is that the same code is working fine on my laptop. I compared the two XML files and found them to be identical... please help ???
NOTE: my laptop is runnig WinXP sp2 while my development machine is running Windows 2003 server