I am trying to pass an object (actually reference) of MyData in a method but getting exception. Channel type is NetTcpBinding.
System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/:myData. The InnerException message was 'Type 'System.RuntimeType' with data contract name 'RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or 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.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: Type 'System.RuntimeType' with data contract name 'RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or 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.
[DataContract]
[KnownType(typeof(System.Type))] //Keeping it here or removing does not make any difference
public class MyData
{
private Type m_MyType = typeof(string);
[DataMember]
public Type MyType //WCF does not like this. If removed of data type changed then ok
{
get { return m_MyType; }
set { m_MyType = value; }
}
private Int32 m_Member1 = 0;
[DataMember]
public Int32 Member1
{
get { return m_Member1; }
set { m_Member1 = value; }
}
}