I want to get back good error info from a WebApi action, so if there's an exception, I do this:
catch (Exception e)
{
return Content(HttpStatusCode.InternalServerError, e);
}
In another WebApi which consumes the first one, I do this so that I can view that exception, in case of an error:
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsJsonAsync<MyModel>();
}
Exception x = await response.Content.ReadAsJsonAsync<Exception>();
// ...look at exception information
The problem is that it's not being serialized/deserialized correctly. Specifically, I'm not getting the array of Error objects in the deserialized Exception object, nor am I getting the StackTrace. It looks like the object is getting serialized incorrectly, so it won't deserialize into the Exception object. For example, the StackTrace property is coming across the wire as "StackTraceString." Obviously, that's not going to deserialize into a property called "StackTrace."
Anyone know why some of the property names are changed when serializing?