YAXLib: Dictionaries with null values crash serializer

Assuming you have a Dictionary, with the valid form:

{
"Key": null
}

An attempt to serialize this throws a null-pointer exception.

Stacktrace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Object.GetType()
   at YAXLib.YAXSerializer.AddObjectToElement(XElement elem, XName alias, Object obj) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 1328
   at YAXLib.YAXSerializer.MakeDictionaryElement(XElement insertionLocation, XName elementName, Object elementValue, YAXDictionaryAttribute dicAttrInst, YAXCollectionAttribute collectionAttrInst) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 1297
   at YAXLib.YAXSerializer.AddObjectToElement(XElement elem, XName alias, Object obj) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 1337
   at YAXLib.YAXSerializer.MakeCollectionElement(XElement insertionLocation, XName elementName, Object elementValue, YAXCollectionAttribute collectionAttrInst, String format) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 1469
   at YAXLib.YAXSerializer.MakeElement(XElement insertionLocation, MemberWrapper member, Object elementValue, Boolean& moveDescOnly, Boolean& alreadyAdded) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 1112
   at YAXLib.YAXSerializer.SerializeBase(Object obj, XName className) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 907
   at YAXLib.YAXSerializer.SerializeBase(Object obj) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 609
   at YAXLib.YAXSerializer.SerializeXDocument(Object obj) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 539
   at YAXLib.YAXSerializer.Serialize(Object obj, XmlWriter xmlWriter) in d:\Codes\GitHub\YAXLib\YAXLib\YAXSerializer.cs:line 380
// snip

The value of null should be allowed/supported as a value in a dictionary.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17

Most upvoted comments

PS @axunonb Nice logo!