Bug 18558 - XML Serializer does not match .Net behavior when using subclasses with multiple XmlElement tags
Summary: XML Serializer does not match .Net behavior when using subclasses with multip...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 3.2.x
Hardware: PC Linux
: Normal normal
Target Milestone: Untriaged
Assignee: Lluis Sanchez
URL:
Depends on:
Blocks:
 
Reported: 2014-03-24 16:14 UTC by Jason
Modified: 2015-05-15 04:38 UTC (History)
3 users (show)

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

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 Jason 2014-03-24 16:14:34 UTC
Under certain circumstances the XmlSerializer does not output the correct XML for elements when multiple XmlElement attributes can match the type due to use of inheritance.

In the following situation:

[XmlType]
public class MainClass
{
   [XmlElement("BElement", typeof(B))]
   [XmlElement("CElement", typeof(C))]
   public A MainClassAbstractMember { get; set; }
}

When an instance of type C is assigned to the member A and MainClass is serialized the resulting Xml written can be:

<MainClass><BElement xsi:type="C"/></MainClass>

when it should be:
<MainClass><CElement/></MainClass>
Comment 1 Jason 2014-04-01 16:09:17 UTC
Pull request with potential fix:
https://github.com/mono/mono/pull/977
Comment 2 Miguel de Icaza [MSFT] 2014-05-23 11:00:41 UTC
Lluis, do you mind reviewing/commenting on the pull request?
Comment 3 Marek Safar 2015-05-15 04:38:23 UTC
Closing, PR was merged