Given:
Problem:
I get errors like the following:
Cannot serialize member [namespace].[entity].[property] of type Iesi.Collections.Generic.ISet`1[[namespace].[entity], [assembly], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.
You must implement a default accessor on Iesi.Collections.Generic.HashedSet`1[[namespace].[entity], [assembly], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it inherits from ICollection.
My questions:
As a sidenote, I tried Googling for help.
- I don't think this is a new problem.
NHibernate serialization has been treated a lot on stackoverflow. See:
Bottom line: use DTOs.
Try using the DataContractSerializer instead. It's more restrictive, but will serialize more.
Dan Rigsby explains the difference between XMLSerializer and DataContractSerializer
Here's an example from one of my posts on stackoverflow:
public XDocument GetProductXML(Product product)
{
var serializer = new DataContractSerializer(typeof(Product));
var document = new XDocument();
using (var writer = document.CreateWriter())
{
serializer.WriteObject(writer, product);
writer.Close();
}
return document;
}
You can never XML Serialize an interface - only a concrete class that implements the interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With