问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/4147923/to-be-xml-serializable-types-which-inherit-from-icollection-must-have-an-implem