我有一个 WCF 服务方法,它需要一个对象,然后使用反射检索其属性。
在客户端,我创建了一个匿名类型对象
var obj = new {FirstName="John", LastName="Doe"}
并将其传递给方法。我遇到了一个例外:
Type '<>f__AnonymousType0`2[System.String,System.String]' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and marking all
of its members you want serialized with the DataMemberAttribute attribute.
See the Microsoft .NET Framework documentation for other supported types.
我不能用序列化属性标记类型或其成员,因为实际上没有明确声明的类型或属性。有没有办法克服这个问题?