tags:

views:

215

answers:

2

I have WCF restful service and have property called Image with Imageclass

[DataMember]
public Image Image { get; set; }

and getting the below error when trying to call the method having a object with above property

System.Runtime.Serialization.SerializationException: Type 'System.Drawing.Bitmap' with data contract name 'Bitmap:http://schemas.datacontract.org/2004/07/System.Drawing' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

A: 

the image class isn't serializable. See http://msdn.microsoft.com/en-us/library/ms730167.aspx for info on KnownTypes

mcintyre321
+2  A: 

The error pretty much tells you how to solve the problem: add System.Drawing.Bitmap as a known type on the contract:

[DataContract]
[KnownType(typeof(System.Drawing.Bitmap))]
class YourContract
{
    [DataMember]
    public Image Image { get; set; }
}
Andrew Hare