开发者

DataContractSerializer KnownType attribute not being respected?

I have a class that is decorated with a KnownType attribute with a type of the class. Is this not allowed?

  [KnownType(typeof(Occ600UIConfig))]
    public class Occ600UIConfig 
    { }

If so, why is the DCS throwing the following exception?

{"Error in line 1 position 387. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data of the 'http://schemas.datacontract.org/2004/07/OCC600.Infrastructure.Dictionary.BusinessEntities:Occ600UIConfig' data contract. The deseriali开发者_运维知识库zer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Occ600UIConfig' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer."}


The KnownType attribute is used to define and "advertise" descendant classes of a base class that might also be used in a given context.

But your data class in WCF should be marked primarily with a [DataContract] attribute (and all members you want to include with a [DataMember] attribute):

[DataContract]
public class Occ600UIConfig 
{ }

If you don't have any inheritance hierarchies, you never need the KnownType attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜