Bug 14101 - Polymorphism deserialization problem: System.Runtime.Serialization (MonoAndroid & MonoTouch) 2.0.5.0 is NOT working as expected
Summary: Polymorphism deserialization problem: System.Runtime.Serialization (MonoAndro...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Runtime.Serialization ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-19 18:29 UTC by stoyannon
Modified: 2018-03-13 12:26 UTC (History)
4 users (show)

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


Attachments
four simple test projects (win8, wp8, android and ios) + output (119.14 KB, application/zip)
2013-08-19 18:40 UTC, stoyannon
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 stoyannon 2013-08-19 18:29:29 UTC
The polymorphism is NOT respected by Xamarin DataContractJsonSerializer (System.Runtime.Serialization.Json) (System.Runtime.Serialization.dll 2.0.5.0) in MonoAndroid & MonoTouch. I attach 4 test projects - Win8, Windows phone 8, Xamarin.Android, and Xamarin.iOS, and one file with the test output of four projects. (Polymorphism is respected ONLY in Win8 & WP8). The serialization testing code is in Win8 project and linked in other three projects.

The object graph is:

TestBase 
    string TestBaseString 
    int TestBaseInt 
Test1:TestBase 
    string Test1String 
    int Test1Int
Test2:TestBase 
    string Test2String 
    int Test2Int
Test 
    TestBase Test1 
    TestBase Test2 
    List<TestBase> TestList

Then the properties in class Test are instantiated as such: Test1 is of type Test1, Test2 is of type Test2, TestList[0] is of type Test1, and TestList[1] is of type Test2.

The problem is that after serializing & deserializing with Xamarin DataContractJsonSerializer the properties in class Test are downgraded to its base : all Test1, Test2, TestList[0], and TestList[1] are now of type TestBase.
Comment 1 stoyannon 2013-08-19 18:40:36 UTC
Created attachment 4664 [details]
four simple test projects (win8, wp8, android and ios) + output
Comment 2 Jonathan Pryor 2013-08-28 15:27:45 UTC
The same bug is present in desktop mono; edit TestSerialization/Win8Serialization/Win8Serialization/TestSerialization.cs and:

1. Add TestSerialization.Main():

	static void Main ()
	{
		new TestSerialization ().Execute ();
	}

2. Change TestSerialization.Log() to use Console.WriteLine(), not Debug.WriteLine():

        public void Log(string info)
        {
            Console.WriteLine (info);
        }

Compile, run:

$ mcs TestSerialization.cs -r:System.Runtime.Serialization.dll
$ mono TestSerialization.exe 
Original:
   Test1:Test.Test1
   Test2:Test.Test2
   TestList[0]:Test.Test1
   TestList[1]:Test.Test2
Deserialized:
   Test1:Test.TestBase
   Test2:Test.TestBase
   TestList[0]:Test.TestBase
   TestList[1]:Test.TestBase
Comment 3 Marek Safar 2018-03-13 12:26:54 UTC
Works as expected with recent Mono versions