title: Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type
body: <p>I am getting this error when attempting to use a Web API controller.</p>
  
  <blockquote>
    <p>Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type</p>
  </blockquote>
  
  <p>the code in my controller is as follows</p>
  
  <pre><code>public IEnumerable&lt;Student&gt; GetAllStudents()
      {
          var allstudents = unitOfWork.StudentRepository.Get(includeProperties: "Groups");
  
  
          return allstudents;
      }
  
      public Student GetStudentByID(Guid id)
      {
          return unitOfWork.StudentRepository.GetByID(id);
      }
  </code></pre>
  
  <p>and my 'Student' class is as follows</p>
  
  <pre><code>public partial class Student
  {
      public Student()
      {
          this.Groups = new HashSet&lt;Group&gt;();
      }
  
      public System.Guid StudentID { get; set; }
      public string Surname { get; set; }
      public string FirstName { get; set; }
      public byte[] Timestamp { get; set; }
  
      public virtual Course Course { get; set; }
      public virtual ICollection&lt;Group&gt; Groups { get; set; }
  }
  </code></pre>
  
  <p>Both methods result in the same error.</p>
  
  <p>My inner exception is as follows</p>
  
  <blockquote>
    <p>Type
    'System.Data.Entity.DynamicProxies.Student_4C97D068E1AD0BA62C3C6E441601FFB7418AD2D635F7F1C14B64F4B2BE32DF9A'
    with data contract name
    'Student_4C97D068E1AD0BA62C3C6E441601FFB7418AD2D635F7F1C14B64F4B2BE32DF9A:<a href="http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies" rel="nofollow">http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies</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>I have a feeling I need to use the <code>KnownType</code> attribute but I'm not exactly sure how to implement it.</p>
  
  <p>Any help would be appreciated</p>