.NET Framework Developer Center >
.NET Development Forums
>
Windows Communication Foundation
>
The "2048" bug of DataContractJsonSerializer class.
The "2048" bug of DataContractJsonSerializer class.
- I found a bug of DataContractJsonSerializer class.
When I use this DataContractJsonSerializer.ReadObject method to deserialize a json string that contains more than 684 non-ANSI characters. I get an exception
There was an error deserializing the object of type WindowsFormsApplication1.Action. The token '"' was expected but found 'æ'.
I think there may be a bug in the DataContractJsonSerializer.ReadObject(Stream) method, with some code like
byte[] bufferNonANSI = new byte[2048];
so that there is no enough space for a string with more than 683 non-ANSI characters.
I hope Microsoft developers for DataContractJsonSerializer class to look into the source code, and check the bug. I want to use the class and need the bug to be fixed.
Thanks.
All Replies
- Hi Jeff,
Can you provide a simple code snipped that reproduces this problem? I tried with the code below, and for all strings from 0-1000 characters I didn't have any problems.
Thanks.
public class Post_938156c7_ccb5_4436_833d_d560b9901750 { public static void Test() { for (int stringSize = 0; stringSize < 1000; stringSize++) { string str = new string((char)0xF000, stringSize); string jsonString = "\"" + str + "\""; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(string)); try { string str2 = (string)dcjs.ReadObject(ms); if (str == str2) { Console.Write("."); } else { Console.WriteLine(); Console.WriteLine("Error, different strings for stringSize = {0}", stringSize); } } catch (Exception e) { Console.WriteLine(); Console.WriteLine("{0}: {1}", e.GetType().FullName, e.Message); } if ((stringSize % 50) == 49) Console.WriteLine(); } } }- Marked As Answer byRiquel_DongModeratorMonday, November 09, 2009 1:35 AM
- Unmarked As Answer byJeff - love coding Monday, November 16, 2009 7:41 AM
- Ok, Riquel_Dong
I give you an String like:string str = new string((char)0x6cd5, stringSize); //which contains 1000 "法" word in chinese.
Please have a try, and then you will get an exception.
Thanks. Please help me, I am waiting for result.
Thank you very much!


