Bugzilla – Bug 669786
Can't use JavaScriptSerializer
Last modified: 2011-03-16 21:39:03 UTC
If you try to use Ajax.BeginForm(), client-side validation (<% Html.EnableClientValidation(); %>), or anything else that uses the JavaScriptSerializer type you get the following exception. This works find in 2.8.x [System.TypeInitializationException]: An exception was thrown by the type initializer for System.Web.Script.Serialization.JavaScriptSerializer at System.Web.Mvc.JsonResult.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x000a2] in /private/tmp/monobuild/build/BUILD/mono-2.10/mcs/class/System.Web.Mvc2/System.Web.Mvc/JsonResult.cs:67 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.10/mcs/class/System.Web.Mvc2/System.Web.Mvc/ControllerActionInvoker.cs:243 at System.Web.Mvc.ControllerActionInvoker+<InvokeActionResultWithFilters>c__AnonStorey38.<>m__47 () [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.10/mcs/class/System.Web.Mvc2/System.Web.Mvc/ControllerActionInvoker.cs:281 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter (IResultFilter filter, System.Web.Mvc.ResultExecutingContext preContext, System.Func`1 continuation) [0x00025] in /private/tmp/monobuild/build/BUILD/mono-2.10/mcs/class/System.Web.Mvc2/System.Web.Mvc/ControllerActionInvoker.cs:255 [System.InvalidCastException]: Cannot cast from source type to destination type. at System.Web.Script.Serialization.JavaScriptSerializer..ctor (System.Web.Script.Serialization.JavaScriptTypeResolver resolver, Boolean registerConverters) [0x0000d] in /private/tmp/monobuild/build/BUILD/mono-2.10/mcs/class/System.Web.Extensions/System.Web.Script.Serialization/JavaScriptSerializer.cs:66 at System.Web.Script.Serialization.JavaScriptSerializer..cctor () [0x00000] in <filename unknown>:0
Please provide a small, self-contained and ready to run test case which demonstrates the issue. After attaching it to the report, please reopen the bug.
Created attachment 415385 [details] MVC project
Sorry, I missed that you actually have to submit the Json form before seeing this error. Please see the attached project.
The attachment doesn't compile because I missed renaming the namespace in Global.asax - set it to ExerciseJson and it will run fine. This has not been fixed in 2.10.1.
This is a duplicate of bug #664813 - please see https://bugzilla.novell.com/show_bug.cgi?id=664813#c1 for explanation and a workaround *** This bug has been marked as a duplicate of bug 664813 ***