Bug 96 - DataContractJsonSerializer crashes deserializing json
Summary: DataContractJsonSerializer crashes deserializing json
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: PC Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
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:


Attachments
Full test case (6.25 KB, application/x-gzip)
2011-07-29 15:54 UTC, Miguel de Icaza [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 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:
Status:
RESOLVED FIXED

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. 

{"Time":161411.232249083,"X":0.055389404296875,"Y":-0.0111236572265625,"Z":-1.031097412109375}

Nothing appears wrong with the generated json. This issues started with the latest release of mt 4.0.4.1
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();
			serializer.WriteObject(ms,accel);
			
			string json = Encoding.Default.GetString(ms.ToArray());
			Console.WriteLine(json);
			
			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 ();


[DataContract]
	public class AccelerometerData
	{
		public AccelerometerData () 
		{
			
		}
		public AccelerometerData (double time,double x,double y, double z)
		{
			Time = time;
			X = x;
			Y = y;
			Z = z;
		}
		[DataMember]
		public double Time {get;set;}
		[DataMember]
		public double X {get;set;}
		[DataMember]
		public double Y {get;set;}
		[DataMember]
		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