尝试序列化Entity Framework对象时出现XML序列化错误 [英] XML serialization errors when trying to serialize Entity Framework objects

查看:96
本文介绍了尝试序列化Entity Framework对象时出现XML序列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些通过实体框架获取的实体。我使用的是Code-First,所以它们是POCO。当我尝试使用XmlSerializer对它们进行XML序列化时,出现以下错误:

I have entities that I am getting via Entity Framework. I'm using Code-First so they're POCOs. When I try to XML Serialize them using XmlSerializer, I get the following error:


类型
System.Data.Entity。 DynamicProxies.Song_C59F4614EED1B7373D79AAB4E7263036C9CF6543274A9D62A9D8494FB01F2127
没想到。使用XmlInclude
或SoapInclude属性可以指定静态未知的
类型。

The type System.Data.Entity.DynamicProxies.Song_C59F4614EED1B7373D79AAB4E7263036C9CF6543274A9D62A9D8494FB01F2127 was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

任何人都有想法

推荐答案

对不起,我知道我来了这有点晚(晚了几年),但是如果不需要代理对象进行延迟加载,则可以执行以下操作:

Sorry, I know I'm coming at this a bit late (a couple YEARS late), but if you don't need the proxy objects for lazy loading, you can do this:

Configuration.ProxyCreationEnabled = false;

在您的上下文中。对我来说就像一个魅力。 Shiv Kumar实际上可以更好地了解原因,但这至少可以使您重新工作(同样,假设您不需要代理)。

in your Context. Worked like a charm for me. Shiv Kumar actually gives better insight into why, but this at least will get you back to work (again, assuming you don't need the proxies).

这篇关于尝试序列化Entity Framework对象时出现XML序列化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆