This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 36829 - XmlSerializer does not support subclasses when serializing sequences of items
Summary: XmlSerializer does not support subclasses when serializing sequences of items
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML (show other bugs)
Version: unspecified
Hardware: All Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-12-10 15:07 UTC by dmitri.toropov
Modified: 2016-04-14 17:02 UTC (History)
4 users (show)

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


Attachments
A solution containing WP8, iOS and Android projects as well as portable library demonstrating the issue (6.70 MB, application/zip)
2015-12-10 15:07 UTC, dmitri.toropov
Details
Fixed the project file (6.70 MB, application/zip)
2015-12-10 15:33 UTC, dmitri.toropov
Details

Description dmitri.toropov 2015-12-10 15:07:30 UTC
Created attachment 14222 [details]
A solution containing WP8, iOS and Android projects as well as portable library demonstrating the issue

I have a portable class library project that contains the following code:
I have defined an object (AnnotationPlacement) which contains a sequence of objects that are either class A (Annotation) or class B (StampPlacement). Now I try to serialize an AnnotationPlacement which contains a subclass of B (DecisionStampPlacement). This works fine on Windows Phone, but the XmlSerializer throws an exception on iOS and Android.

Expected behavior: no exception is thrown, XML can be generated (as on Windows Phone).

My system is (all available updates are installed):

Xamarin Studio
Version 5.10.1 (build 6)
Installation UUID: cd5de8aa-e5ec-4753-adb8-94cd3953973a
Runtime:
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

Xamarin.Profiler
Not Installed

Apple Developer Tools
Xcode 7.2 (9548)
Build 7C68

Xamarin.iOS
Version: 9.2.1.54 (Enterprise Edition)
Hash: eb4c1ef
Branch: master
Build date: 2015-12-01 02:12:30-0500

Xamarin.Android
Version: 6.0.0.34 (Starter Edition)
Android SDK: /Users/dmitri.toropov/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Xamarin Android Player
Not Installed

Xamarin.Mac
Not Installed

Build Information
Release ID: 510010006
Git revision: 0b60eecdb531933734519c13257d16a780274aab
Build date: 2015-12-04 20:28:20-05
Xamarin addins: 9876fd7c9837977178411ec7375b4352c0a0d6af
Build lane: monodevelop-lion-cycle6-baseline

Operating System
Mac OS X 10.11.2
Darwin Dmitrys-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 1 dmitri.toropov 2015-12-10 15:27:39 UTC
The inner-most exception says: The type TestXmlSerializer.DecisionStampPlacement may not be used in this context.

Stack Trace:
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListContent (System.Object container, System.Xml.Serialization.TypeData listType, System.Xml.Serialization.ListMap map, System.Object ob, System.Text.StringBuilder targetString) [0x0025c] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs:463 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList) [0x00099] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs:255 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x0000c] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs:202 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.String element, System.String namesp) [0x00036] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs:190 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.String element, System.String namesp, Boolean isNullable, Boolean needType, Boolean writeWrappingElem) [0x001ff] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs:154 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteRoot (System.Object ob) [0x00056] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs:75 
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Object o, System.Xml.Serialization.XmlSerializationWriter writer) [0x0001c] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:417 
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00064] in /Users/builder/data/lanes/2506/eb4c1ef1/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:480
Comment 2 dmitri.toropov 2015-12-10 15:33:36 UTC
Created attachment 14223 [details]
Fixed the project file

Fixed the project file: some of the unneeded dependencies were removed, but Xamarin Studio has not updated the project file so it failed to build.
Comment 3 Cody Beyer (MSFT) 2015-12-14 17:25:45 UTC
This bug still occurs on the latest Xamarin 3 versions noted below, and therefore I do not consider this a regression at this time.

=== Xamarin Studio ===

Version 5.9.8 (build 0)
Installation UUID: 17ea749b-4dee-43b5-afaa-5925246add77
Runtime:
	Mono 4.0.5 ((detached/1d8d582)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400050001

=== Xamarin.Android ===

Version: 5.1.9.0 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.2 (9548)
Build 7C68

=== Xamarin.iOS ===

Version: 9.1.0.31 (Business Edition)
Hash: bae2cdb
Branch: master
Build date: 2015-11-09 17:44:57-0500

=== Xamarin.Mac ===

Version: 2.4.0.109 (Business Edition)

=== Build Information ===

Release ID: 509080000
Git revision: cc5f6e5658589ca7f46210c57fad947e75f30abd
Build date: 2015-10-21 19:27:41-04
Xamarin addins: d77f191bd7d3451adf837b85b38f2b7c60004400

=== Operating System ===

Mac OS X 10.11.2
Darwin Codys-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 4 marcos.henrich 2016-01-11 18:11:11 UTC
Hello Dmitri,

Thanks for the bug report and test case.

I was able to reproduce the issue on the devices, the pull request below fixes this.
https://github.com/mono/mono/pull/2419
Comment 5 marcos.henrich 2016-01-28 18:07:19 UTC
Fixed in mono/master 80eb29884c136f0de78a5f4c988bda83d24eb9f0
https://github.com/mono/mono/commit/80eb29884c136f0de78a5f4c988bda83d24eb9f0

Fixed in cycle7 mono/mono-4.3.2-branch 03f2ff096a5310f985b20624c5de4fb5c4ff119d
https://github.com/mono/mono/commit/03f2ff096a5310f985b20624c5de4fb5c4ff119d

Pending approval on cycle 6 service release 2
Comment 6 Rajneesh Kumar 2016-02-11 17:40:56 UTC
I have tried to reproduce this issue with the latest stable build and I am able to reproduce this. I observed that on emulator it shows that "There was an error generating the XML document".

Screencast: http://www.screencast.com/t/P7XXzJw91Y

I also checked this issue with the following latest Master build:

MonoFramework-MDK-4.3.2.431.macos10.xamarin.universal_9f44a62acf718d91320420c1c77e855a63f3c3f9
XamarinStudio-6.0.0.3416_7efe2abe40ba288e7b560660da2c5983d85310c6
mono-android-6.0.99-513_e36688250f2cd85df66024012b8e5ac852505e88

and I observed that emulator and simulator shows the generated XML Document.

Screencast: http://www.screencast.com/t/QFMXFIvUrVDy

This issue has been fixed and working fine, hence I am closing this issue.

Thanks..!

Build Info: https://gist.github.com/Rajneesh360Logica/116fa1a27f3ae8bee3cc

Note You need to log in before you can comment on or make changes to this bug.