我有WCF restful服务,并且有名为Image with Imageclass的属性
[DataMember]
public Image Image { get; set; }
并在尝试调用具有上述属性的对象的方法时出现下面的错误
数据协定名称为‘System.Runtime.Serialization.SerializationException::http://schemas.datacontract.org/2004/07/System.Drawing’的位图类型'System.Drawing.Bitmap‘不应为空。静态地将任何未知类型添加到已知类型列表中-例如,通过使用KnownTypeAttribute属性或通过将它们添加到传递给DataContractSerializer的已知类型列表中。
发布于 2009-08-06 06:54:38
错误很大程度上告诉您如何解决问题:将System.Drawing.Bitmap
作为已知类型添加到约定中:
[DataContract]
[KnownType(typeof(System.Drawing.Bitmap))]
class YourContract
{
[DataMember]
public Image Image { get; set; }
}
发布于 2009-08-06 06:52:14
image类不可序列化。有关KnownTypes的信息,请参阅http://msdn.microsoft.com/en-us/library/ms730167.aspx
https://stackoverflow.com/questions/1239392
复制相似问题