title: wcf Serialization issue with complex types
body: <p>possibly a duplicate of <a href="https://stackoverflow.com/questions/8794594/type-not-expected-using-datacontractserializer-but-its-just-a-simple-class">this question</a></p>
  
  <p>I'm trying to serialize a set of objects using the standard <code>DataSerializer</code> which is used with <code>wcf</code>.</p>
  
  <p>object structure:</p>
  
  <pre><code>[KnownType(typeof(PersonnelClassProperty))]
  [KnownType(typeof(ResourceClassProperty))]
  [KnownType(typeof(Person))]
  [KnownType(typeof(PersonProperty))]
  [KnownType(typeof(ResourceDefinitionProperty))]
  [DataContract]
  public class Person: ResourceDefinition
  {
     [DataMember]
     public guid id {get; set;}
  
     [DataMember]
     public IList&lt;PersonProperty&gt; personProperties {get; set;}
  
     [DataMember]
     public IList&lt;PersonnelClass&gt; personnelClasses {get; set;}
  }
  </code></pre>
  
  <p>PersonProperty : ResourceDefinitionProperty</p>
  
  <ul>
  <li>PersonnelClassProperty</li>
  </ul>
  
  <p>PersonnelClass : ResourceClass</p>
  
  <ul>
  <li>Persons</li>
  <li>PersonnelClassProperty</li>
  </ul>
  
  <p>PersonnelClassPoperty : ResourceClassProperty</p>
  
  <p>The Above structure is mapped using <code>Nhibernate</code>. so the Base classes are <code>abstract classes</code> with base properties which we override into the main classes. we are using this so we can use a generic class for calling the CRUD functions in <code>Nhibernate</code>.</p>
  
  <p>the first problem this poses is a circular reference, we fixed this. by resetting the lists of the objects we eliminated a circular reference problem.</p>
  
  <p>we also loop through the properties and the associated class properties to get them, as they are being lazily loaded through <code>nHibernate</code></p>
  
  <p>this allowed me to generate some test data. we now have one <code>personnelclass</code> with a <code>personnelclassproperty</code>. these are being retrieved fine on its own. next we have a <code>person</code>. we added a reference to the <code>personnelclass</code>, and a <code>personnelclassproperty</code>. in the database we have an extra table that holds the reference for the link between the person and <code>personnelclass</code>, as this a <code>many-to-many relationShip</code>. the <code>personProperty</code> has a reference to a single <code>personnelClassproperty</code>, so a <code>FK</code> suffices here.</p>
  
  <p>here, we run into the second problem, a serialization exception occurs: </p>
  
  <blockquote>
    <p>'PersonnelClassPropertyProxy' with data contract name 'PersonnelClassPropertyProxy:<a href="http://schemas.datacontract.org/2004/07/" rel="nofollow noreferrer">http://schemas.datacontract.org/2004/07/</a>' 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.</p>
  </blockquote>
  
  <p>so taken from the question mentioned in the first line i proceeded to add the <code>[DataContract]</code>, <code>[DataMember]</code> and <code>[KnownType(typeof(T))]</code> attributes to the classes mentioned above. where <code>T</code> is of course the correct type.</p>
  
  <p>what happens is that we send person objects through wcf to a receiving party, which works fine if the is no link between the <code>personProperty</code> and the <code>personnelClassProperty</code>, but if we add a <code>personproperty</code> with a link to <code>PersonnelClassProperty</code>, we get the exception mentioned above.</p>
  
  <p>all the examples and questions i see online work the same way</p>
  
  <p>so concretely; what am i doing wrong? or what am i forgetting here?</p>
  
  <p>i'll try to update the question with more code to illustrate the objects we use.</p>
  
  <p><strong>edit:</strong> I updated the structure of the <code>Person</code> object to show what i have done with the <code>KnownTypes</code>. note that this also holds the <code>personnelClassProperty</code> type, i have also did this for the <code>PersonProperty</code> object, because that is the actual class that holds the <code>PersonnelClassProperty</code> object, but a list of <code>personProperties</code> is used in <code>Person</code>. this doesn't work either.</p>