Bug 16744 - DataContractJSONSerializer on MonoTouch produces different result to Microsoft.Net version.
Summary: DataContractJSONSerializer on MonoTouch produces different result to Microsof...
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Atsushi Eno
URL:
: 17707 ()
Depends on:
Blocks:
 
Reported: 2013-12-11 14:13 UTC by Jon Goldberger [MSFT]
Modified: 2014-02-26 04:34 UTC (History)
6 users (show)

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


Attachments
Test project (32.72 KB, application/zip)
2013-12-11 14:13 UTC, Jon Goldberger [MSFT]
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:
VERIFIED FIXED

Description Jon Goldberger [MSFT] 2013-12-11 14:13:21 UTC
Created attachment 5641 [details]
Test project

From case:
We have hit a high priority issue for us in that the DataContractJSonSerializer class in System.Runtime.Serialization is not producing the same result on Windows and iOS.

I've built some sample code here which illustrates the problem: https://www.dropbox.com/s/7xnek08vhv1svm4/JDCSTest.zip

As you can see if you open the JDCSTest.sln in Visual Studio and run the console app you can see it deserialises the json and then reports it is the correct type and contains 1 appointment.

If you open JDCSTest.IOS.sln in Xamarin Studio and run it on the ipad simulator the ReadObject method fails with the following error:

System.Runtime.Serialization.SerializationException: Deserialization has failed ---> System.Exception: Typed value is invalid. Line 1, position 887.
at System.Xml.XmlReader.ReadContentAsDecimal () [0x00012] in /Developer/MonoTouch/Source/mono/mcs/class/System.XML/System.Xml/XmlReader.cs:1267
at System.Xml.XmlDictionaryReader.ReadContentAsDecimal () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReader.cs:298
at System.Xml.XmlDictionaryReader.ReadElementContentAsDecimal () [0x00012] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReaderAutoGen.cs:484
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x001cf] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:115
at System.Runtime.Serialization.Json.TypeMap.Deserialize (System.Runtime.Serialization.Json.JsonSerializationReader jsr) [0x000f4] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:241
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x0047c] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:183
at System.Runtime.Serialization.Json.JsonSerializationReader.DeserializeGenericCollection (System.Type collectionType, System.Type elementType) [0x001f9] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:338
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00469] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:180
at System.Runtime.Serialization.Json.TypeMap.Deserialize (System.Runtime.Serialization.Json.JsonSerializationReader jsr) [0x000f4] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:241
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x0047c] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:183
at System.Runtime.Serialization.Json.JsonSerializationReader.DeserializeGenericCollection (System.Type collectionType, System.Type elementType) [0x001f9] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:338
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00469] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:180
at System.Runtime.Serialization.Json.TypeMap.Deserialize (System.Runtime.Serialization.Json.JsonSerializationReader jsr) [0x000f4] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:241
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x0047c] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:183
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadRoot () [0x0000d] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:66
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlReader reader, Boolean verifyObjectName) [0x00045] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:194
--- End of inner exception stack trace ---
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlReader reader, Boolean verifyObjectName) [0x00062] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:198
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:183
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:173
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.IO.Stream stream) [0x00018] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:165
at DeserialiseTest.Test.Deserialise () [0x0002b] in /Volumes/c$/Temp/jdcs/JDCSTest/DeserialiseTest/Test.cs:46
at JDCSTest.IOS.JDCSTest_IOSViewController.RunTest (MonoTouch.Foundation.NSObject sender) [0x00008] in /Volumes/c$/Temp/jdcs/JDCSTest/JDCSTest.IOS/JDCSTest.IOSViewController.cs:56
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at JDCSTest.IOS.Application.Main (System.String[] args) [0x00008] in /Volumes/c$/Temp/jdcs/JDCSTest/JDCSTest.IOS/Main.cs:16

Ideally a solution that requires no change to the data contracts would be ideal as we have to go on supporting a legacy system which uses them as they are now. I haven't tested this in MonoAndroid yet but we'd also need the same result in there as Microsoft.Net produces.

I am using the following version of Xamarin Studio:
=== Xamarin Studio ===

Version 4.2.2 (build 2)
Installation UUID: 7cd1cc06-607e-4278-bbf4-381ff8bce70b
Runtime:
Mono 3.2.5 ((no/964e8f0)
GTK+ 2.24.20 theme: Raleigh
GTK# (2.12.0.0)
Package version: 302050000

=== Apple Developer Tools ===

Xcode 5.0 (3332.25)
Build 5A1413

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: 7.0.4.209 (Enterprise Edition)
Hash: 23a0827
Branch:
Build date: 2013-11-11 16:04:00-0500

=== Xamarin.Android ===

Version: 4.10.1 (Enterprise Edition)
Android SDK: /Users/david.ingham/Library/Developer/Xamarin/android-sdk-mac_x86
Supported Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
4.0 (API level 14)
4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Build Information ===

Release ID: 402020002
Git revision: c5f82958ae7d9af652b44b87ceff777b3ad19b91
Build date: 2013-11-19 15:35:40+0000
Xamarin addins: a4044fee09138f6fd031a9944b7caaeb51e57e80

=== Operating System ===

Mac OS X 10.9.0
Darwin hsw10473.cse-servelec.com 13.0.0 Darwin Kernel Version 13.0.0
Thu Sep 19 22:22:27 PDT 2013
root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
Comment 2 David Ingham 2013-12-12 09:01:58 UTC
I've done some further investigation and it appear to cause the problem when deseralising a nullable integer (ActualDuration on our AttendeeContract).
Comment 3 David Ingham 2013-12-12 11:39:59 UTC
Seems to be more like any null json parameter... not just nullable types.
Comment 4 Jon Goldberger [MSFT] 2013-12-12 15:02:23 UTC
Looks like this is a Mono bug. Running a console app against Mono and the same error occurs. There is a console app in the attached zip.
Comment 6 Miguel de Icaza [MSFT] 2013-12-12 16:20:33 UTC
Atsushi would you mind looking at this bug?
Comment 7 Atsushi Eno 2014-02-06 03:12:55 UTC
fixed in master [21cb413].
Comment 8 Atin 2014-02-11 13:26:40 UTC
Today, We have checked this issue with attached test project in Bug. When we open JDCSTest.IOS.sln in Xamarin Studio and run it on the ipad simulator it run successfully without any error.

here is the screencast for the same: http://www.screencast.com/t/GwfSSB9ul

Environment details:
ML 10.8.5
XS 4.2.4(build 14)- d36f82139fd61a0cda68d5baabb1c7b8402116b9
MT 7.0.7
Xcode 5.0

Hence marking this as Verified.
Comment 10 Mikayla Hutchinson [MSFT] 2014-02-11 17:20:32 UTC
*** Bug 17707 has been marked as a duplicate of this bug. ***