Bug 31089 - ArgumentNullException with Generic List and XmlAttribute during Deserialitazion
Summary: ArgumentNullException with Generic List and XmlAttribute during Deserialitazion
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-06-13 12:16 UTC by Gabor Molnar
Modified: 2015-06-17 11:22 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
example code highlighting the exception (1.53 KB, text/plain)
2015-06-13 12:16 UTC, Gabor Molnar
Details
Updated example with public setter (1.52 KB, text/plain)
2015-06-15 15:43 UTC, Gabor Molnar
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Gabor Molnar 2015-06-13 12:16:13 UTC
The attached code throws ArgumentNullException on Ubuntu 15.04, with Mono 4.0.1 (tarball Thu May 28 09:08:28 UTC 2015):

System.ArgumentNullException: Argument cannot be null. Parameter name: elementType   
at System.Array.CreateInstance (System.Type elementType, System.Int32[] lengths) [0x0000c] in <filename unknown>:0    
at System.Array.CreateInstance (System.Type elementType, Int32 length) [0x0000b] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadListString (System.Xml.Serialization.XmlTypeMapping typeMap, System.String values) [0x00055] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.GetValueFromXmlString (System.String value, System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlTypeMapping typeMap) [0x0000c] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadAttributeMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList) [0x0004e] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList, Boolean readBySoapOrder) [0x00000] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstanceMembers (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00007] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstance (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x000df] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00031] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObjectElement (System.Xml.Serialization.XmlTypeMapElementInfo elem) [0x00069] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadListElement (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, System.Object list, Boolean canCreateInstance) [0x000ff] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList, Boolean readBySoapOrder) [0x0054c] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstanceMembers (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00007] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstance (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x000df] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00031] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObjectElement (System.Xml.Serialization.XmlTypeMapElementInfo elem) [0x00069] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadListElement (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, System.Object list, Boolean canCreateInstance) [0x000ff] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList, Boolean readBySoapOrder) [0x0054c] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstanceMembers (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00007] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstance (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x000df] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00031] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObjectElement (System.Xml.Serialization.XmlTypeMapElementInfo elem) [0x00069] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadListElement (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, System.Object list, Boolean canCreateInstance) [0x000ff] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList, Boolean readBySoapOrder) [0x0054c] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstanceMembers (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00007] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstance (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x000df] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00031] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObjectElement (System.Xml.Serialization.XmlTypeMapElementInfo elem) [0x00069] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadListElement (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, System.Object list, Boolean canCreateInstance) [0x000ff] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList, Boolean readBySoapOrder) [0x0054c] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstanceMembers (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00007] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstance (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x000df] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00031] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot (System.Xml.Serialization.XmlTypeMapping rootMap) [0x0006a] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot () [0x00028] in <filename unknown>:0    
at System.Xml.Serialization.XmlSerializer.Deserialize (System.Xml.Serialization.XmlSerializationReader reader) [0x0001c] in <filename unknown>:0


This code runs fine on Windows 8.1 and .NET 4.5.
The issue seem to be specific to generic collections and XmlAttribute (using XmlElement would work correctly).
Comment 1 Gabor Molnar 2015-06-13 12:16:58 UTC
Created attachment 11597 [details]
example code highlighting the exception
Comment 2 Marek Safar 2015-06-15 13:38:06 UTC
Mono master/4.2 throws different error which looks like valid error, you have private setter. Strangely .net does not throw it even if it generates same serialization code which looks like

   DataClass o = new DataClass();
    if (o.IntList == null)
    {
        o.IntList = new List<int>();
    }

if IntList getter does not return null, it works on .net otherwise it throws same MAE which probably mean that .net does some delayed access check but I could not find any trigger for this and extracted code fails on .net and mono in same way.
Comment 3 Gabor Molnar 2015-06-15 14:57:38 UTC
My bad, the actual code I made the example from has public setter. The exception is the same though (on 4.0.1).

It's strange for me that XmlElement worked on Mono, but XmlAtribute didn't.
Comment 4 Gabor Molnar 2015-06-15 15:43:10 UTC
Created attachment 11612 [details]
Updated example with public setter
Comment 5 Marek Safar 2015-06-17 11:22:54 UTC
Version with public setter works on mono 4.2 and master