I have a webAPI 2 controller, Currently it is throwing an exception, and this is being sent back to the client in a response message. 500 internal server error, the exception it's self is serialised and I can see the json representation of it in fiddler. (json pasted below)
I have been trying to find a way to de-serialize this exception back to a an .NET Exception object, but keep getting the error:
"Member 'ClassName' was not found."
currently in my client I am trying to deserialise the exception via the following code.
if (apiResponse.ResponseCode.Equals(500)) // Unhandled exception on server
{
var exceptionObject = await response.Content.ReadAsAsync<Exception>();
}
How do I properly de-serialize this exception object on my client side application? ideally I should be able to get back the original System.InvalidOperationException` object.
Below is the Response I am trying to de-serialize as captured in fiddler:
HTTP/1.1 500 Internal Server Error Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/10.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 30 Sep 2015 13:43:42 GMT Content-Length: 1556
{"Message":"An error has occurred.","ExceptionMessage":"UrlHelper.Link must not return null.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Results.CreatedAtRouteNegotiatedContentResult
1.Execute()\r\n at System.Web.Http.Results.CreatedAtRouteNegotiatedContentResult1.ExecuteAsync(CancellationToken cancellationToken)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}