virendra:Hi All,
I just want to create my object from XML. The xml does not contan any kind of BrokenRule collection.
Hi,
I am relatively new the CSLA framework. I got the same problem as yours in the inner exception.
In the outer exception, I got something like ..
"There was error reflecting type ListAbc."
This class is derived from BusinessListBase<>. In the innerexception, I got the following error...
"Can not serialize member CSLA.Core.BusinessBase.BrokenRulesCollections of type CSLA.Validation.BrokenRulesCollection can not be serialized." Now on checking the innerexception property of this, I got the same error message as yours "CSLA.Validation.BrokenRule can not be serialized because it does not have a parameterless constructor".
For now, I have changed in the original code of CSLA framework without knowing the repurcutions. I have included a parameterless internal overloaded constructor (besides the one which is already there with few parameters).
When I referenced the new dll, and tried to serialize using the XMLSerializer, I was able to serialize the object. So I have the answer of the problem but still need to know the cause of this issue.
Regards,
Rajat.
DO NOT implement ISerializable for this purpose!!
ISerializable allows you to control how the BinaryFormatter serializes your object - it DOES NOT affect how the XmlSerializer works. All you'd do by implementing ISerializable is mess up cloning and the data portal.
There's a different interface you need to implement to control the XmlSerializer (I don't remember the interface name). It didn't used to be documented, as it was for internal use in the DataSet only, but I think in .NET 2.0 Microsoft documented the interface, so it is probably OK to use.
I don't know if that interface is honored by WCF though, so you might want to check on that ahead of time. Somehow I doubt they support it, because WCF has a new mechanism for serialization. However, they do support <Serializable()> and ISerializable, so it is hard to say for sure.
My recommendation, as always, is that if you want to expose your objects as XML, you should define a formal DTO (data transfer object) and write code to put your data into/out of that DTO - then let the XmlSerializer (or WCF) serialize the DTO into/out of XML.
That approach gives you much better control over the process, and decouples your object from the XML contract you are defining - making your code more maintainable in the long term.
Copyright (c) Marimer LLC