Interface web api XmlMediaTypeFormatter异常

Interface web api XmlMediaTypeFormatter异常,interface,inversion-of-control,asp.net-web-api,xml-formatting,Interface,Inversion Of Control,Asp.net Web Api,Xml Formatting,我想使用IoC/web api框架的依赖项解析器进行解耦 XmlFormatter无法序列化接口,。。。好啊但是,如果我不能返回xml,IoC和DependencyResolver的目的是什么 我甚至不能这样做: (我的ApicController中的方法) public HttpResponseMessage Get() { IEnumerable projects=new List(){new Project(),new Project()}。选择(p=>p as Project); htt

我想使用IoC/web api框架的依赖项解析器进行解耦

XmlFormatter无法序列化接口,。。。好啊但是,如果我不能返回xml,IoC和DependencyResolver的目的是什么

我甚至不能这样做: (我的ApicController中的方法)

public HttpResponseMessage Get()
{
IEnumerable projects=new List(){new Project(),new Project()}。选择(p=>p as Project);
httpresponsemessageresponse=Request.CreateResponse(HttpStatusCode.OK,projects);
返回响应;
}
我创建了一个IProjects列表,并将它们转换为“Project”。但在创建响应时,我得到了以下信息:

配置的格式化程序 “System.Web.Http.Tracing.Tracers.XmlMediaTypeFormatterTracer”不能 写入类型为“WhereSelectListIterator”2的对象

这是一个XmlMediaTypeFormatterTracer?我不希望跟踪在序列化时抛出错误。(顺便说一句:我用自己的XMLformatter替换了标准的XMLformatter。但是“XmlMediaTypeFormatterTracer”抛出异常。。。 信息:我在使用标准格式化程序时遇到相同的错误)


即使我实现了自己的xmlformatter,为什么还要调用这个XmlMediaTypeFormatterTracer?

在应用程序中启用跟踪了吗?如果是,跟踪逻辑将格式化程序包装到其a包装跟踪格式化程序中。

您在应用程序中启用了跟踪吗?如果是,跟踪逻辑将格式化程序包装到其a包装跟踪格式化程序中。

我的问题已通过解决

config.Formatters.XmlFormatter.UseXmlSerializer=false

我的问题用

config.Formatters.XmlFormatter.UseXmlSerializer=false

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;
        }