ASP.NET Web API: XMLFormatter thinks he can write Json-objects

johnboy

New Member
i have a method like this:\[code\]public JObject Get(int id) { return new JObject(new JProperty("Test", "Test")); }\[/code\]It works fine if I request JSON, but if I request XML i get an HTTP-Errorcode 500 from the web api framework (no exception).It seems likely that the XMLformatter thinks he can write json.I can test it with:\[code\]bool test = GlobalConfiguration.Configuration.Formatters.XmlFormatter.CanWriteType(typeof(JArray)); bool test2 = GlobalConfiguration.Configuration.Formatters.XmlFormatter.CanWriteType(typeof(JObject)); bool test3 = GlobalConfiguration.Configuration.Formatters.XmlFormatter.CanWriteType(typeof(JProperty)); bool test4 = GlobalConfiguration.Configuration.Formatters.XmlFormatter.CanWriteType(typeof(JValue));\[/code\]It always returns "true".I dont want to remove the xmlformatter, but it is not acceptable that the server throws an HTTP Error 500 which I dont produce and cant solve.The best would be that the XMLformatter can serialize the object...
 
Back
Top