I have a WCF service, with a method UpdateProperty that take a PropertyValue in parameter :
void UpdateProperty(PropertyValue propertyValue)
[DataContract]
public class PropertyValue
{
[DataMember]
public string Property { get; private set; }
[DataMember]
public object Value { get; private set; }
}
I'm trying to call the method with a KeyValuePair as Value, and I'm getting this error :
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:propertyValue. The InnerException message was 'Error in line 1 position 544. Element 'http://schemas.datacontract.org/2004/07/MyProject.DataContracts:Value' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:KeyValuePairOfanyTypeanyType'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to 'KeyValuePairOfanyTypeanyType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to the serializer.'. Please see InnerException for more details."
I tried to add a KnownType on my class but I still get the error :
[KnownType(typeof(KeyValuePair<object, object>))]
Any idea why ? I'm using other KeyValuePair in other method (as parameter) without problem...
In my SOAP body, I have :
<d4p1:Value xmlns:d7p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" i:type="d7p1:KeyValuePairOfanyTypeanyType">
<d7p1:key>test</d7p1:key>
<d7p1:value>test</d7p1:value>
</d4p1:Value>
KeyValuePair<,>
that you are serializing over the wire? Is it really aKeyValuePair<object, object>
or is it, say, aKeyValuePair<string, string>
? – dbcValue
. Mark your classPropertyValue
with[KnownType( typeof(MyType) )]
,MyType
is the Type that you give him in theValue
Property. – Rabban[KnownType(typeof(KeyValuePair<object, object>))]
attribute onPropertyValue
? Did you modify the contract on both the client and server sides to include this known type? – dbc