Reputation: 9269
I want to use IoC / the dependency resolver of the web api framework for decoupling.
The XmlFormatter cant serialize interfaces,... Ok. But what would be the purpose of IoC and the DependencyResolver if I cant return xml?
I cant even do this: (Method in my ApiController)
public HttpResponseMessage Get()
{
IEnumerable<Project> projects = new List<IProject>() { new Project(), new Project() }.Select(p => p as Project);
HttpResponseMessage response = Request.CreateResponse<IEnumerable<Project>>(HttpStatusCode.OK, projects);
return response;
}
I create a list of IProjects and cast them to 'Project'. But while creating the response I get this:
The configured formatter 'System.Web.Http.Tracing.Tracers.XmlMediaTypeFormatterTracer' cannot write an object of type 'WhereSelectListIterator`2'.
That is a XmlMediaTypeFormatterTracer? I dont want tracing that throws errors while serialization. (BTW: I replaced the standard XMLformatter with my own one. However "XmlMediaTypeFormatterTracer" throws the exception... Info: I get the same error while using the standard formatter)
Why is this XmlMediaTypeFormatterTracer called even if I implement my own xmlformatter?
Upvotes: 0
Views: 2670
Reputation: 428
my problem solved with
config.Formatters.XmlFormatter.UseXmlSerializer = false;
Upvotes: 4
Reputation: 57989
Have you enabled Tracing in your application? If yes, the Tracing logic wraps formatters into its a wrapper tracer formatters.
Upvotes: 0