Bug 39663 - InvalidOperationException when serializing classes that emit CS0108 warning
Summary: InvalidOperationException when serializing classes that emit CS0108 warning
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: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-03-15 19:20 UTC by Ethan Lee
Modified: 2016-04-12 13:36 UTC (History)
2 users (show)

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


Attachments
Test Case (575 bytes, text/x-csharp)
2016-03-15 19:20 UTC, Ethan Lee
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 Ethan Lee 2016-03-15 19:20:40 UTC
Created attachment 15418 [details]
Test Case

When attempting to serialize classes that redundantly declare variables that exist in base classes, the XmlSerializer constructor will fail claiming "The XML element named 'X' from namespace '' is already present in the current scope," which is certainly a valid issue (as the compiler warning will tell you) but will work fine with .NET anyway.

Attached is a test case demonstrating a redundant variable in a serializable subclass. The trace should look something like this and should still exist even in upstream, if I'm reading the Git log correctly:

Unhandled Exception:
System.InvalidOperationException: There was an error reflecting type 'MonoXmlRuiner.SomeObject'. ---> System.InvalidOperationException: There was an error reflecting field 'price'. ---> System.InvalidOperationException: The XML element named 'price' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.
  at System.Xml.Serialization.ClassMap.AddMember (System.Xml.Serialization.XmlTypeMapMember member) [0x0027a] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs:369 
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, Boolean isBaseType) [0x0021b] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:375 
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, Boolean isBaseType) [0x0022a] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:377 
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00074] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:215 
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x0017b] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:235 
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00047] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:190 
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraTypes, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x0004d] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:227 
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:175 
  at MonoXmlRuiner.Program.Main (System.String[] args) [0x00017] in /home/flibitijibibo/MonoXmlRuiner.cs:33 
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: There was an error reflecting type 'MonoXmlRuiner.SomeObject'. ---> System.InvalidOperationException: There was an error reflecting field 'price'. ---> System.InvalidOperationException: The XML element named 'price' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.
  at System.Xml.Serialization.ClassMap.AddMember (System.Xml.Serialization.XmlTypeMapMember member) [0x0027a] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs:369 
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, Boolean isBaseType) [0x0021b] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:375 
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, Boolean isBaseType) [0x0022a] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:377 
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00074] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:215 
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x0017b] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:235 
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00047] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs:190 
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraTypes, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x0004d] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:227 
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in /builddir/build/BUILD/mono-4.0.5/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:175 
  at MonoXmlRuiner.Program.Main (System.String[] args) [0x00017] in /home/flibitijibibo/MonoXmlRuiner.cs:33
Comment 1 Marek Safar 2016-04-12 13:36:33 UTC
Already fixed in Mono 4.2