I have an HttpResponseMessage
whose Content
property I know to be of type Exception
, or some subclass thereof. Now I'm trying to deserialize that content like so:
var exception = httpResponseMessage.Content.ReadAsAsync<Exception>().Result;
But when I do this, it throws an AggregateException
with the message
System.AggregateException: One or more errors occurred. ---> Newtonsoft.Json.JsonReaderException: Error parsing boolean value. Path '', line 0, position 0.
If I view the content as a string, I can see from the Json that it's of type `DivideByZeroException':
{"ClassName":"System.DivideByZeroException","Message":"Attempted to divide by zero.","Data": ... etc...
I'd be happy to get back an Exception
object - but does ReadAsAsync<>
not support deserializing an object into its base class type? If not, then what's the best way to detect what type of object I should be creating?