.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > The "2048" bug of DataContractJsonSerializer class.
Ask a questionAsk a question
 

QuestionThe "2048" bug of DataContractJsonSerializer class.

  • Tuesday, November 03, 2009 4:30 AMJeff - love coding Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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. 


    Signature

All Replies

  • Tuesday, November 03, 2009 5:41 PMCarlos FigueiraMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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();
                }
            }
        }
    
    
  • Monday, November 16, 2009 7:44 AMJeff - love coding Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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.

  • Thursday, November 26, 2009 7:31 AMJeff - love coding Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Please help me, I am waiting for result.

    Thank you very much!