WCF return "object" using KnownType attribute
<p>I'm having issues with returning an object from a WCF service.  A minimal example is included</p>

<pre><code>[ServiceContract]
public interface IService1
{
    [OperationContract]
    object GetObjectData();
}
</code></pre>

<p>When the GetObjectData() method returns a string then everything works fine and my client can read the data, but when it returns a different object for instance, an object in a common assembly:</p>

<pre><code>[DataContract]
[KnownType(typeof(TestObject))]
public class TestObject
{
    [DataMember]
    public string StringProperty { get; set; }

    [DataMember]
    public int IntProperty { get; set; }
}
</code></pre>

<p>then the client call to the webservice method crashes.  From reading around on the internet the KnownType attribute (as above) should have solved all of my issues but I'm now getting the below error from my client.  Thanks for any help.</p>

<p>{"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter <a href="http://tempuri.org/:GetObjectDataResult" rel="nofollow">http://tempuri.org/:GetObjectDataResult</a>. The InnerException message was 'Error in line 1 position 289. Element '<a href="http://tempuri.org/:GetObjectDataResult" rel="nofollow">http://tempuri.org/:GetObjectDataResult</a>' contains data from a type that maps to the name '<a href="http://schemas.datacontract.org/2004/07/ClassLibrary1Common:TestObject" rel="nofollow">http://schemas.datacontract.org/2004/07/ClassLibrary1Common:TestObject</a>'. 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 'TestObject' 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."}</p>