要XML序列化,它自ICollection继承的类型必须添加的实现 [英] To be XML serializable, types which inherit from ICollection must have an implementation of Add

查看:636
本文介绍了要XML序列化,它自ICollection继承的类型必须添加的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有里昂证券(1.x的框架)从现有的项目,我想在一个新的.NET 4.0的项目使用对象。在生产中所使用的对象,我实在无法将它们转换为2.x或EF无需对象的2套。

在我的C#web服务(当我尝试运行它)我收到以下错误:


 要XML序列化,它从ICollection的继承类型必须
有各级添加(objectname.object)的实现
他们的继承层次结构。 objectname.objectList不
实施加(objectname.object)。


就像我说的这些对象都写在vb.net CSLA对象。我不知道去哪里找这一点。它是.NET 4.0中试图与CSLA 1.x的一个问题或者是一个Web服务的问题(因为这些物体从未使用Web服务最初)?

有没有人对我应该在哪里看弄清楚这个问题的想法?我应该建议转换为CSLA 2.X?

任何建议都AP preciated!


解决方案

这是一个XmlSerializer限制;如果事情看起来像数据列表,它会想通过Add方法将项目添加到它。

如果你有机会获得这些对象,考虑增加这样的方法。我不记得是否希望加入(对象)与添加(SOMETYPE),所以尝试两个。

如果您的的有超过那些对象的控制......这将是很难。这将是更快地写为对象的新DTO层,而不是试图以某种方式修补它。

I have CSLA (1.x framework) objects from an existing project that I'm trying to use in a new .Net 4.0 project. The objects are being used in production and I really can't convert them to 2.x or EF without having 2 sets of objects.

In my c# webservice (when I try to run it) I am getting the following error:

To be XML serializable, types which inherit from ICollection must
have an implementation of Add(objectname.object) at all levels
of their inheritance hierarchy. objectname.objectList does not
implement Add(objectname.object).

Like I said these objects are CSLA objects written in vb.net. I don't know where to look on this one. Is it an issue of .Net 4.0 trying to talk to CSLA 1.x or is it a web service issue (as these objects never used web services originally)?

Does anyone have an idea about where I should look to figure out this issue? Should I suggest converting to CSLA 2.x?

Any suggestions are appreciated!

解决方案

This is an XmlSerializer limitation; if something looks like a list of data, it will want to Add items to it via the Add method.

If you have access to those objects, consider adding such a method. I can't recall whether it wants Add(object) vs Add(SomeType) so try both.

If you don't have control over those objects... it will be hard. It would be quicker to write a new DTO layer for the objects than to try to patch it somehow.

这篇关于要XML序列化,它自ICollection继承的类型必须添加的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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