Xml Serialization and additional nullable properties

Posts   
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 21-Jun-2007 17:53:07   

I have added some additional properties to the generated entities that I set once at load from various sources. If any of the properties are nullable types, the deserialization throws an error if the value is null.

I have traced it down to the XmlHelper.XmlValueToObject method. Using Lutz sunglasses , I think the problem is that if the type is Nullable, it does not check for xmlValue.Length <= 0 before the converstion of the type, it does that after the case. So the Convert routines are getting called with an empty string, thowing the error.

In my case, I have a nullable Decimal, which ends up calling Convert.ToDecimal("").

using .NET 2.0 runtime - 2.0.7.416

Stack Trace:

System.InvalidOperationException: There is an error in XML document (1, 90897). ---> System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Decimal.Parse(String s, IFormatProvider provider) at System.Convert.ToDecimal(String value) at SD.LLBLGen.Pro.ORMSupportClasses.XmlHelper.XmlValueToObject(String typeName, String xmlValue) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Dictionary2 processedObjectIDs, List1 nodeEntityReferences) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlNode node) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlReader reader) at System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderServices.Read5_GetLeLoanResponse() at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer9.Deserialize(XmlSerializationReader reader) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 22-Jun-2007 10:58:01   

Sounds like bug. Will fix it.

(edit) Fixed in next build. (2.0.7.0622)

Frans Bouma | Lead developer LLBLGen Pro