I have a simple object with a propery (I have more properties, simple ints and strings);
[DataMember]
public virtual IList<MailAddress> DistributionList { get; set; }
I read this object using NHibernate, resulting in the property beeing of type NHibernate.Collection.Generic.PersistentGenericList.
I get the following error when looking at the WCF log;
There was an error while trying to serialize parameter http://tempuri.org/:StartReportDistributionResult. The InnerException message was
Type 'Miros.Models.MailAddress' with data contract name 'MailAddress:http://schemas.datacontract.org/2004/07/Miros.Models' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.'. Please see InnerException for more details.
Now this should indicate that there is something wrong with serialization. So I added code which test the object through the DataContractSerializer, from this question Has anyone created a DataContract testing tool?. This works fine...
Now if I change the property;
myObject.DistributionList = myObject.DistributionList.ToList();
WCF is happy. What is going on here? How can I find out what is the problem.
ToString
on the exception object and paste the entire result into your question. Also, have you tried applying the KnownTypeAttribute to the class with the property? It may be annoying but it might solve your issue. – user1228