title: Web Api IHttpActionResult HttpContent
body: <p>I want all my controllers calls to return a IHttpActionResult, so I made a class implementing this interface. When someone makes a GET call obviously some complex data is going to be sent back to the client inside this IHttpActionResult response object. Now I am having trouble inserting my content into my HttpResponseMessage. Here's what my error looks like when I make a call to one of my GET methods. </p>
  
  <blockquote>
    <p>{"Message":"An error has occurred.","ExceptionMessage":"Cannot convert type 'XXXXX.DomainModels.News.AllNewsItems' to 'System.Net.Http.HttpContent'","ExceptionType":"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException","StackTrace":"   at CallSite.Target(Closure , CallSite , Object )<br>
    at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)<br>
    at XXXXAPI.PresentationLayer.Helpers.ActionResultGet.ExecuteAsync(CancellationToken cancellationToken) in </p>
  </blockquote>
  
  <p>As you can see I am casting my content to HttpContent, that obviously is not doing the trick... And If I remove the cast I still get the same error. How do I get my complex type into this content?</p>
  
  <pre><code>public class ActionResultGet : IHttpActionResult
  {
      private readonly HttpRequestMessage _request;
      private readonly dynamic _content;
  
      public ActionResultGet(HttpRequestMessage request, dynamic content)
      {
          _request = request;
          _content = content;
      }
  
      public Task&lt;HttpResponseMessage&gt; ExecuteAsync(
          System.Threading.CancellationToken cancellationToken)
      {
          if(_content == null)
          {
              var badResponse = new HttpResponseMessage()
              {
                  StatusCode = HttpStatusCode.NotFound,
                  Content = (HttpContent)this._content
              };
  
              return Task.FromResult(badResponse);
          }
  
          var response = new HttpResponseMessage()
          {
              StatusCode = HttpStatusCode.OK,
              Content = (HttpContent)this._content
          };
  
          return Task.FromResult(response);
      }
  }
  </code></pre>