No MediaTypeFormatter for application/xml???

Topics: Web Api
Mar 28, 2012 at 1:31 PM

I seem to be stuck at the moment when deserializing a response message with response.Content.ReadAs<T>(). I get

No 'MediaTypeFormatter' is available to read an object of type 'KeyPair' with the media type 'application/xml'. A few key headers from Fiddler below..

Accept: application/xml

Charset: utf-8

Content-Type: application/xml

The weird thing is that I'm succeeding with this type of call (a POST with return message) on another type. I've compared the two approaches extensively looking at the headers, Web API code, serialization attributes on the .net type. Everything about the approach looks the same yet it complains about this one not having a formatter. I didn't need a custom formatter for the other type so why this one? BTW I'm using version 5 as of now.

Any help would be appreciated,


Mar 28, 2012 at 3:35 PM

Turn on using the data contract xml serializer.

config.Formatters.XmlFormatter.UseDataContractSerializer = true;

Mar 28, 2012 at 3:42 PM

Thanks for the reply. I actually noticed I was deriving the class from another whose properties had no representation in the incoming response. I suspect the DataContractSerializer would be more lenient and simply ignore the extra properties?


Anyway, thanks..

Mar 28, 2012 at 3:43 PM


FYI if you didn't know this project is dead.

The new project is ASP.Net Web API, the information about this is on this sites home page.

Mar 28, 2012 at 4:09 PM

Thank for last bit of info. I honestly didn't know of this change (hell I just got off the REST starter kit lol).