title: Always have error "The ObjectContent 1 type failed to serialize the response body..."
body: <p>I use Web api to retrieve data from the database. I only have 1 table "tblMessage" and want to get data from that table.</p>
  
  <p>I set everything up but then when I run the website. the error always say</p>
  
  <blockquote>
    <p>The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml</p>
  </blockquote>
  
  <p>I read some posts on stackoverflow that sayid the error could be fixed by telling the browser to output data in json format. After that, the error becomes</p>
  
  <blockquote>
    <p>The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json</p>
  </blockquote>
  
  <p>I have tried all solutions from the following posts, but they dont fix the problem ( browser reports the same error)</p>
  
  <p><a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/a5adf07b-e622-4a12-872d-40c753417645/web-api-error-the-objectcontent1-type-failed-to-serialize-the-response-body-for-content" rel="nofollow noreferrer">Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type</a> </p>
  
  <p><a href="https://stackoverflow.com/questions/14053109/failed-to-serialize-the-response-body-for-content-type">Failed to serialize the response body for content type</a>    </p>
  
  <p><a href="https://stackoverflow.com/questions/12936713/web-api-error-the-objectcontent1-type-failed-to-serialize-the-response-body">Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type</a>    </p>
  
  <p>What exactly this error is?</p>
  
  <pre><code>public interface IMessage
  {
      IQueryable&lt;Message&gt; GetAll();
  }
  
  public class Message
  {
      [Key]
      public int i_StmID { get; set; }
      public string vch_MsgString { get; set; } 
  }
  
  public class EFDBContext : DbContext
  {
      public DbSet&lt;Message&gt; Message { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
          modelBuilder.Entity&lt;Message&gt;().ToTable("tblMessage");
      }
  }
  
  public class MessageRepository : IMessage
  {
      private EFDBContext context = new EFDBContext();
  
      public IQueryable&lt;Message&gt; GetAll()
      {
          return context.tblMessage;
      }
  }
  
  public class MessageController : ApiController
  {
      public IMessage repo = new MessageRepository();
  
      public IEnumerable&lt;Message&gt; GetAllMsg()
      {
          return repo.GetAll();
      }
  }
  </code></pre>