To be XML serializable, types which inherit from ICollection must have an implementation of Add
Asked Answered
A

1

3

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!

Augsburg answered 10/11, 2010 at 18:50 Comment(0)
A
7

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.

Austronesian answered 10/11, 2010 at 19:20 Comment(3)
Thank you for your answer... What does DTO stand for? I do have control over those objects however, they are also being used in another project which would mean I would have to include more people in this type of change. So your DTO option is intriguing...Augsburg
@Jeff - Data Transfer Object - i.e. a set of classes specifically for the purposes of serializationAustronesian
@Jeff - but in this case it sounds like you should be able to just add the missing Add?Austronesian

© 2022 - 2024 — McMap. All rights reserved.