title: DataContractResolver / KnownType issue when custom class contains another custom class
body: <p>I'm trying to output a list of objects to a json format using the DataContractJsonSerializer class however I keep running into the following error.</p>
  
  <pre><code>Type 'Castle.Proxies.JokeCategoryProxy' with data contract name 
  'JokeCategoryProxy:http://schemas.datacontract.org/2004/07/Castle.Proxies' 
  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.
  </code></pre>
  
  <p>I know this has been answered before but it only seems to happen when in my object a have a property which is another custom object.</p>
  
  <pre><code>[DataContract]
  [KnownType(typeof(ModelBase&lt;int&gt;))]
  public class Joke : ModelBase&lt;int&gt;
  {
      [DataMember]
      public virtual string JokeText { get; set; }
  
      [DataMember]
      public virtual JokeCategory JokeCategory { get; set; }
  }
  
  [DataContract]
  [KnownType(typeof(ModelBase&lt;int&gt;))]
  public class JokeCategory : ModelBase&lt;int&gt;
  {
      [DataMember]
      public virtual string Name { get; set; }
  }
  </code></pre>
  
  <p>As you can see the Joke model contains a Joke Category object, if I remove the Joke Category and simply have an int (JokeCategoryId) the error disappears, although a solution, not an ideal one as I would like to have the Category available without having to query again.</p>
  
  <p>Below is the code I'm using to generate the json</p>
  
  <pre><code>    public static ContentResult JsonResponse&lt;TReturnType&gt;(this Controller controller, TReturnType data)
      {
          using (var oStream = new System.IO.MemoryStream())
          {
              new DataContractJsonSerializer(typeof(TReturnType)).WriteObject(oStream, data);
  
              return new ContentResult
              {
                  ContentType = "application/json",
                  Content = Encoding.UTF8.GetString(oStream.ToArray()),
                  ContentEncoding = Encoding.UTF8
              };
          }
      }
  </code></pre>
  
  <p>What confuses me the most is that the error references Castle.Proxies.JokeCategoryProxy (where did this come from?!)</p>
  
  <p>Any suggestions?</p>