Modify JsonFormatter on the config to use DataContractJsonSerializer.
My action looks like this:
---------------------------
[HttpGet]
public string GetGreeting()
{
throw new InvalidOperationException("invalid operation is being performed");
return "Hello";
}
Response returned (NOTE: notice how the Error information looks like):
------------------------------------------------------------------------
HTTP/1.1 500 Internal Server Error
Content-Length: 1050
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 15 Jun 2012 16:42:53 GMT
"<Error><Message>An error has occurred.<\/Message><ExceptionMessage>invalid operation is being performed<\/ExceptionMessage><ExceptionType>System.InvalidOperationException<\/ExceptionType><StackTrace> at MvcWebApi.MainTests.Tests.BugReproTests.BugReproTestsController.GetGreeting() in C:\\Users\\kichalla\\Documents\\Visual Studio 2010\\Projects\\ClassLibrary3\\ClassLibrary3\\Class1.cs:line 71
\u000a at lambda_method(Closure , Object , Object[] )
\u000a at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
\u000a at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
\u000a at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
\u000a at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)<\/StackTrace><\/Error>"
Comments: This is the behavior from DCJS for serializing any type that implements IXmlSerializable.
My action looks like this:
---------------------------
[HttpGet]
public string GetGreeting()
{
throw new InvalidOperationException("invalid operation is being performed");
return "Hello";
}
Response returned (NOTE: notice how the Error information looks like):
------------------------------------------------------------------------
HTTP/1.1 500 Internal Server Error
Content-Length: 1050
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 15 Jun 2012 16:42:53 GMT
"<Error><Message>An error has occurred.<\/Message><ExceptionMessage>invalid operation is being performed<\/ExceptionMessage><ExceptionType>System.InvalidOperationException<\/ExceptionType><StackTrace> at MvcWebApi.MainTests.Tests.BugReproTests.BugReproTestsController.GetGreeting() in C:\\Users\\kichalla\\Documents\\Visual Studio 2010\\Projects\\ClassLibrary3\\ClassLibrary3\\Class1.cs:line 71
\u000a at lambda_method(Closure , Object , Object[] )
\u000a at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
\u000a at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
\u000a at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
\u000a at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)<\/StackTrace><\/Error>"
Comments: This is the behavior from DCJS for serializing any type that implements IXmlSerializable.