标签:
错误提示:
System.InvalidOperationException: 生成 XML 文档时出错。 ---> System.InvalidOperationException: 不应是类型 System.Data.Entity.DynamicProxies.FrDocMain_6A6FA4013EBB9F316ECF2126518C20341055E52EDEBA21C97E7E8430E7B15A70。使用 XmlInclude 或 SoapInclude 特性静态指定非已知的类型。 在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5_FrDocMain(String n, String ns, FrDocMain o, Boolean isNullable, Boolean needType) 在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_FrDocument(String n, String ns, FrDocument o, Boolean isNullable, Boolean needType) 在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write10_FrDocument(Object o) 在 Microsoft.Xml.Serialization.GeneratedAssembly.FrDocumentSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer) 在 System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) --- 内部异常堆栈跟踪的结尾 --- 在 System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) 在 System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces) 在 System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue) 在 System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) 在 System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) 在 System.Web.Services.Protocols.WebServiceHandler.Invoke()
解决办法:
public FrDocMain GetItem(int docId)
{
//db.Configuration.ProxyCreationEnabled = false;
return db.FrDocMains.SingleOrDefault(p => p.DocID == docId);
}
加上被注释的那句就可以了。
ef 对象无法序列化的问题(System.Data.Entity.DynamicProxies)
标签:
原文地址:http://www.cnblogs.com/sportdog/p/5301110.html