Bug 96 - DataContractJsonSerializer crashes deserializing json
Summary: DataContractJsonSerializer crashes deserializing json
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: PC Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-07-27 19:22 UTC by James Clancey
Modified: 2011-07-29 16:08 UTC (History)
2 users (show)

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

Full test case (6.25 KB, application/x-gzip)
2011-07-29 15:54 UTC, Miguel de Icaza [MSFT]

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 Developer Community or GitHub 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:

Description James Clancey 2011-07-27 19:22:38 UTC
The DataContractJsonSerializer is throwing an error when you try and re serialize an object back. The error is thrown from JsonReader.cs in line 509. It is trying to validate the json. The json was created using the DataContractSerializer.
Here is a sample of the json code. 


Nothing appears wrong with the generated json. This issues started with the latest release of mt
Comment 1 Miguel de Icaza [MSFT] 2011-07-28 23:27:19 UTC
Can you provide the actual code fragment that produces this crash?
Comment 2 James Clancey 2011-07-29 00:12:14 UTC
Here is a code snippet that crashes.

			var accel = new AccelerometerData(2.0,1.0,1.0,1.0);
			DataContractJsonSerializer serializer = new DataContractJsonSerializer(accel.GetType());
			MemoryStream ms = new MemoryStream();
			string json = Encoding.Default.GetString(ms.ToArray());
			ms = new MemoryStream (Encoding.Unicode.GetBytes (json));
			System.Runtime.Serialization.Json.DataContractJsonSerializer deserializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer (typeof(AccelerometerData));
			accel = deserializer.ReadObject (ms) as AccelerometerData;
			ms.Close ();

	public class AccelerometerData
		public AccelerometerData () 
		public AccelerometerData (double time,double x,double y, double z)
			Time = time;
			X = x;
			Y = y;
			Z = z;
		public double Time {get;set;}
		public double X {get;set;}
		public double Y {get;set;}
		public double Z {get;set;}
Comment 3 Miguel de Icaza [MSFT] 2011-07-29 15:54:16 UTC
Created attachment 37 [details]
Full test case
Comment 4 Miguel de Icaza [MSFT] 2011-07-29 15:54:40 UTC
Will have a fix in the new version
Comment 5 Miguel de Icaza [MSFT] 2011-07-29 16:08:29 UTC
Will have a fix in the new version
Comment 6 Miguel de Icaza [MSFT] 2011-07-29 16:08:46 UTC
Fixed in the upcoming version