WCF Serialization Exception - NetDataContractSerializer

 ̄綄美尐妖づ 提交于 2019-12-10 14:43:56

问题


I am getting an error while trying to send an collection of data over to our service. If however I add only a single item to the collection then it works fines. As soon as I add more then one item I get the following error

The use of type 'SmartTrade.Shared.Common.PaymentTerm' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.

So the key thing to note here is that I can send the collection (IList<>) with a single item. I have increased the MaxReceivedMessageSize and the MaxArrayLength to what I think is more then reasonable.

Can anybody help me out here


回答1:


Finally I worked it out. There was a property in one of the base class that only had a getter property and did not have a setter property. So I had to add a setter property




回答2:


An alternative to adding a pointless setter would be to mark the property to be ignored by serialization.

This can be done by decorating your property with System.Runtime.Serialization.IgnoreDataMemberAttribute

Example:

public class Whatever
{
    [IgnoreDataMember] // this won't be serialized now
    public List<string> Things
    {
        get { return _things; }
    }
}


来源:https://stackoverflow.com/questions/9780766/wcf-serialization-exception-netdatacontractserializer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!