title: Declaring Known Types for data contracts in different assemblies
body: <p>I have a method in a WCF service which returns a complex type (myComplexResult), which includes as one of its members a List (Of Common.myBaseClass).  I want this list to hold items which can variously be of type Foo.myClass1 and Bar.myClass2, both of which inherit from Common.myBaseClass.  Note that all of these classes are defined in different assemblies.</p>
  
  <p>The service throws this exception:</p>
  
  <blockquote>
    <p>Type
    'Foo.myClass1'
    with data contract name
    'myClass1:<a href="http://mynamespace/foo/" rel="nofollow noreferrer">http://mynamespace/foo/</a>'
    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.</p>
  </blockquote>
  
  <p>Okay, so I realise that I need to declare myClass1 and myClass2 as known types of myBaseClass so that the DataContractSerializer knows what to do with them.  I can't do the obvious thing and decorate the myBaseClass class with KnownType attributes for myClass1 and myClass2, since this would mean adding references to the Foo and Bar assemblies, which causes a circular dependency.</p>
  
  <p>I was hoping to use declaredTypes in my config file and I tried this:</p>
  
  <pre><code>&lt;system.runtime.serialization &gt;
      &lt;dataContractSerializer &gt;
          &lt;declaredTypes &gt;
              &lt;add type ="Common.myBaseClass, Common"&gt;
                  &lt;knownType type ="Foo.myClass1, Foo" /&gt;
                  &lt;knownType type ="Bar.myClass2, Bar" /&gt;
              &lt;/add&gt;
          &lt;/declaredTypes&gt;
      &lt;/dataContractSerializer&gt;
  &lt;/system.runtime.serialization&gt;
  </code></pre>
  
  <p>That didn't seem to help, so I tried to add a KnownType attribute to myComplexResult:</p>
  
  <pre><code>  &lt;DataContract(name:="myComplexResult", [namespace]:="http://mynamespace/coo/")&gt; _
      &lt;KnownType(GetType(Foo.myClass1))&gt; _
      Public Class myComplexResult
          &lt;DataMember(name:="myList")&gt; _
          Public myList As List(Of Common.myBaseClass)
  </code></pre>
  
  <p>But I'm still getting the same error.  Help!  What do I do?</p>