Asp.net mvc Xml序列化无法写入类型为';x';
我想使用XmlFormatter在MVC Web API中将类序列化为响应,但在创建响应时出现以下异常:Asp.net mvc Xml序列化无法写入类型为';x';,asp.net-mvc,api,web,xml-serialization,Asp.net Mvc,Api,Web,Xml Serialization,我想使用XmlFormatter在MVC Web API中将类序列化为响应,但在创建响应时出现以下异常: MediaTypeFormatter formatter = Configuration.Formatters.XmlFormatter; HttpResponseMessage resp = Request.CreateResponse<Model>(HttpStatusCode.OK, value: modelObject, formatter: formatter); 出
MediaTypeFormatter formatter = Configuration.Formatters.XmlFormatter;
HttpResponseMessage resp = Request.CreateResponse<Model>(HttpStatusCode.OK, value: modelObject, formatter: formatter);
出什么事了?我在网上搜寻这个错误的线索,几个小时后什么也没找到 答案很简单
模型
类缺少一个默认构造函数,这导致了一个奇怪的不可调试异常
更多信息:为我节省了数小时的搜索时间。像这样简单的事情。:-)非常感谢。
The configured formatter 'System.Web.Http.Tracing.Tracers.XmlMediaTypeFormatterTracer' cannot write an object of type 'Model'.