title: Rewriting API from .Net Framework to .netcore ,Getting 'System.NotSupportedException' in attempt to get file stream
body: <p>I am Migrating one of projects to .NET CORE MVC ,</p>
  <ol>
  <li>Previous code had API to Upload document, re-written same</li>
  <li>Rewritten Above Code to below code , used &quot;using
  Microsoft.AspNetCore.Mvc.WebApiCompatShim&quot; to get HttpRequestMessage</li>
  </ol>
  <p>[Older Code: Working Fine in .NET FRAMEWORK]</p>
  <pre><code>public HttpResponseMessage UploadFile(string filetype)//old code
      {
          Stream file = Request.Content.ReadAsStreamAsync().Result;
          string id;
          id = DocumentHelper.SaveDocument(filetype, file);
  
          return Request.CreateResponse&lt;string&gt;(HttpStatusCode.OK, id);
      }
  
  
  public  HttpResponseMessage UploadFile(string filetype)//Re-Written Code
      {
          HttpRequestMessageFeature requestMessage = new HttpRequestMessageFeature(Request.HttpContext);
          HttpRequestMessage httpRequestMessage = requestMessage.HttpRequestMessage;
          Stream file = httpRequestMessage.Content.ReadAsStreamAsync().Result;
          string id;
          id = DocumentHelper.SaveDocument(filetype, file);
  
          return httpRequestMessage.CreateResponse&lt;string&gt;(HttpStatusCode.OK, id);
      }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/sRXDd.png" rel="nofollow noreferrer">Quickwatch for ReWritten Code when trying to read content</a></p>
  <p><a href="https://i.stack.imgur.com/sRXDd.png" rel="nofollow noreferrer">[1]: https://i.stack.imgur.com/cc4AF.png</a></p>
  <p>Tried using Request.Body with stream reader, and enabled buffering.</p>
  <p>Any Pointers How to read the stream from Microsoft.AspNetCore.HTTP.HttpRequest,I AM TRYING TO AVOID async function that would force me to change return type</p>