XmlSerializer 更新后停止工作
我正在使用 XmlSerializer。到目前为止我还没有遇到任何问题。我将 Silverlight 从 4 更新到 5,同时还将 WCF RIA 服务从 v1 SP1 更新到 v1 SP2。现在下面的行给了我一个错误。
XmlSerializer s = new XmlSerializer(typeof(MyCustomObject));
错误是:
System.InvalidOperationException:System.ServiceModel.DomainServices.Client.EntityConflict无法序列化,因为它没有无参数构造函数。
我正在使用的对象(示例中的MyCustomObject)没有以任何方式改变,所以我开始认为是 SL5 或新的 RIA 服务破坏了我的代码。我没有找到任何重大更改文档或提到这可能会发生。我不知道为什么它有 EntityConflict 问题,因为我没有在对象中使用任何实体。
有没有人见过这样的错误和/或知道如何解决它?
更新!
错误消息在 EntityConflict 之前显示的最后一个属性是实体。我认为这会有所不同,但它以前一直有效。我还想知道为什么序列化器已经尝试在构造函数中序列化对象?
I'm using XmlSerializer. I've had no problems with it until now. I updated Silverlight from 4 to 5 and at the same time also updated the WCF RIA Services from v1 SP1 to v1 SP2. Now the following line gives me an error.
XmlSerializer s = new XmlSerializer(typeof(MyCustomObject));
The error is:
System.InvalidOperationException: System.ServiceModel.DomainServices.Client.EntityConflict cannot be serialized because it does not have a parameterless constructor.
The object I'm using (MyCustomObject in the sample) has not changed in any way so I'm starting to think it's either SL5 or the new RIA Services that is breaking my code. I didn't find any breaking changes document or mentions that this could happen. I don't know why it has a problem with EntityConflict since I'm not using any entities within my object.
Has anyone seen an error like this and/or know how to solve it?
UPDATE!
The final property that the error message says before EntityConflict is an Entity. I think that makes a difference but it has been working before. I'd also like to know why the serializer already tries to serialize the object in the constructor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定为什么会发生这种情况,RIA 服务实体不是 XmlSerialized 对象,并且实体本身没有用 [Serializable] 属性修饰。您是否在客户端添加了用 [Serialized] 装饰实体的部分类或以某种方式修改了代码生成?
I am not sure why this would be happening, RIA Services entities are not XmlSerializable objects and the entities themselves are not decorated with the [Serializable] attribute. Have you added partial classes on the client side which decorate the entities with [Serializable] or modified the code generation in some way?
我通过使用中间可序列化 POCO 对象解决了这个问题,这些对象是我的自定义对象的副本(从实体继承)。 POCO 对象没有继承自 Entity。我刚刚从原始实体对象更新了它们的值。然后他们连载得很好。当然,当您反序列化时,您需要从 POCO 对象更新实体对象。
I got around this problem by using intermediary serializable POCO objects which were copies of my custom objects (which were inherited from Entity). The POCO objects did not inherit from Entity. I just updated their values from the original Entity objects. They then serialized quite nicely. Of course, when you de-serialize you need to update your Entity objects from the POCO objects.