[Mono-bugs] [Bug 664813] New: System.Web.Mvc.JsonResult.ExecuteResult no longer works, exception is thrown at System.Web.Script.Serialization.JavaScriptSerializer..ctor when application is compiled with dmcs (but still works with gmcs)
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sun Jan 16 09:12:19 EST 2011
https://bugzilla.novell.com/show_bug.cgi?id=664813
https://bugzilla.novell.com/show_bug.cgi?id=664813#c0
Summary: System.Web.Mvc.JsonResult.ExecuteResult no longer
works, exception is thrown at
System.Web.Script.Serialization.JavaScriptSerializer..
ctor when application is compiled with dmcs (but still
works with gmcs)
Classification: Mono
Product: Mono: Class Libraries
Version: SVN
Platform: x86
OS/Version: Linux
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Sys.Web
AssignedTo: mhabersack at novell.com
ReportedBy: denisv at post.skynet.lt
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.13)
Gecko/20101203 Firefox/3.6.13
Version: Git e9267b1f2166f2b6bcdd74841700a35a9749da88
OS: Debian Squeeze
ASP.NET MVC applications that return JSON from controller actions appear to
have been broken by a semi-recent commit; Mono compiled from Git around October
2010 used to work.
The following is displayed by actions that return JsonResult:
------------------------------------------------------------------------------
Server Error in '/' Application
Cannot cast from source type to destination type.
Description: HTTP 500. Error processing request.
Stack Trace:
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) [0x00000] in <filename unknown>:0
at System.Web.Script.Serialization.JavaScriptSerializer..cctor () [0x00000]
in <filename unknown>:0
Version information: Mono Runtime Version: 2.11 (master/c855584 Sun Jan 16
01:42:24 EET 2011); ASP.NET Version: 4.0.30319.1
------------------------------------------------------------------------------
An example that does not require a full ASP.NET application is provided below.
It works with mcs, gmcs but not dmcs (my ASP.NET application uses xsp4).
Reproducible: Always
Steps to Reproduce:
[mono] /tmp/bugtest @ cat test.cs
using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Mvc;
class Program
{
static void Main()
{
var obj = new { Foo = "1", Bar = 2 };
var jsonResult = new JsonResult();
jsonResult.Data = obj;
jsonResult.ContentType = "application/json";
jsonResult.ContentEncoding = Encoding.ASCII;
jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
var httpRequest = new HttpRequest("test.aspx",
"http://localhost/test.aspx", "");
var httpResponseWriter = new StringWriter();
var httpResponse = new HttpResponse(httpResponseWriter);
var httpContext = new HttpContext(httpRequest, httpResponse);
var httpContextWrapper = new HttpContextWrapper(httpContext);
var controllerContext = new ControllerContext();
controllerContext.HttpContext = httpContextWrapper;
jsonResult.ExecuteResult(controllerContext);
Console.WriteLine(httpResponseWriter.ToString());
}
}
[mono] /tmp/bugtest @ gmcs -r:System.Web -r:System.Web.Mvc
-r:System.Web.Abstractions test.cs && mono test.exe
{"Foo":"1","Bar":2}
[mono] /tmp/bugtest @ dmcs -r:System.Web -r:System.Web.Mvc
-r:System.Web.Abstractions test.cs && mono test.exe
Unhandled Exception: System.TypeInitializationException: An exception was
thrown by the type initializer for
System.Web.Script.Serialization.JavaScriptSerializer --->
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) [0x00000] in <filename unknown>:0
at System.Web.Script.Serialization.JavaScriptSerializer..cctor () [0x00000]
in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Web.Mvc.JsonResult.ExecuteResult (System.Web.Mvc.ControllerContext
context) [0x00000] in <filename unknown>:0
at Program.Main () [0x00000] in <filename unknown>:0
Actual Results:
Exception is thrown when application is compiled by dmcs.
Expected Results:
No exception is thrown.
ASP.NET MVC applications could use JavaScriptSerializer manually and return
ContentResult as a workaround, but this requires extensive changes to the
applicaiton.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list