Bug 27755 - System.Web.Script.Serialization.JavaScriptSerializer DeserializeObject bug with " over more than one line
Summary: System.Web.Script.Serialization.JavaScriptSerializer DeserializeObject bug wi...
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 3.12.0
Hardware: Other Linux
: --- normal
Target Milestone: ---
Assignee: Alexander Kyte
Depends on:
Reported: 2015-03-08 08:27 UTC by Ernstjan Freriks
Modified: 2015-03-10 09:20 UTC (History)
3 users (show)

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

Repro (881 bytes, application/zip)
2015-03-08 13:19 UTC, Alexander Kyte

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:

Description Ernstjan Freriks 2015-03-08 08:27:31 UTC
There is an discrepancy between System.Web.Script.Serialization.JavaScriptSerializer found in System.Web.Extensions.dll from the .NET 4.0/4.5 runtime under Windows and under Mono (Linux). The problem lies in the deserialisation of a string to a anonymous .NET object, when a double quote character '"' is started and closed on another line (after a line break). This works correctly in .NET, but not under Mono.

Example code:

        public JsonResult Test1()
            string json_that_works = @"
                  content:""      <div id=\""calendar\""><div>   ""   

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return Json(serializer.DeserializeObject(json_that_works), JsonRequestBehavior.AllowGet);

        public JsonResult Test2()
            string json_that_fails = @"
<div id=\""calendar\""><div>   

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return Json(serializer.DeserializeObject(json_that_fails), JsonRequestBehavior.AllowGet);

Method Test1 correctly works under Mono, method Test2 will fail with this error:

Invalid object passed in, key value expected (76)

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Web.Extensions.
Exception stack trace:
at System.Web.Script.Serialization.JsonDeserializer.ProcessCharacter (char) <0x0090c>
at System.Web.Script.Serialization.JsonDeserializer.Deserialize (System.IO.TextReader) <0x0009f>
at System.Web.Script.Serialization.Json.Deserialize (System.IO.TextReader,System.Web.Script.Serialization.JavaScriptSerializer) <0x00057>
at System.Web.Script.Serialization.Json.Deserialize (string,System.Web.Script.Serialization.JavaScriptSerializer) <0x0004f>
at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObjectInternal (string) <0x0001b>
at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject (string) <0x0001b>
at Kejay.MapStickPresenter.Controllers.HomeController.Test2 () <0x00047>
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[]) <0x00063>
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) <0x00033>
at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2<string, object>) <0x001af>
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) <0x0002f>
at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) <0x00037>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41 () <0x0001f>
at System.Web.Mvc.Async.AsyncResultWrapper/<>c__DisplayClass8`1<System.Web.Mvc.ActionResult>.<BeginSynchronous>b__7 (System.IAsyncResult) <0x00027>
at System.Web.Mvc.Async.AsyncResultWrapper/WrappedAsyncResult`1<System.Web.Mvc.ActionResult>.End () <0x0005f>
at System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.ActionResult> (System.IAsyncResult,object) <0x00037>
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (System.IAsyncResult) <0x0003b>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c__DisplayClass37/<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33 () <0x0007f>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49 () <0x00047>
Comment 1 Alexander Kyte 2015-03-08 13:19:39 UTC
Created attachment 10207 [details]

Can reproduce.
Comment 2 Alexander Kyte 2015-03-08 15:22:33 UTC
Fix created which passes repro test and looks to not introduce any new regressions. Review needed.