Why can't a DataMember in WCF return Type?

前端 未结 2 1347
温柔的废话
温柔的废话 2021-01-17 14:18

Trying to get this to work, with no luck:

[DataMember]
public Type ParameterType { get; set;}
2条回答
  •  清歌不尽
    2021-01-17 14:52

    Any field or property that returns System.Type is not serializable using WCF because, at runtime, the actual type of the object is System.RuntimeType, which is marked as internal, and thus cannot be automatically serialized by the DataContractSerializer, which can only serialize publicly accessible types.

    However, you could write an IXmlSerializer wrapper around System.Type that will pull out the information you intend to transfer.

提交回复
热议问题