ASP.NET Web API issue: This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked.
When calling an ASP.NET Web API it failed with the following error message:
"An error has occurred." ExceptionMessage "This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked."
ExceptionType "System.Web.HttpException" StackTrace at System.Web.HttpRequest.GetInputStream(Boolean persistEntityBody, Boolean disableMaxRequestLength) at System.Web.HttpRequestWrapper.GetBufferedInputStream() at System.Web.Http.WebHost.SeekableBufferedRequestStream..ctor(HttpRequestBase request) at System.Web.Http.WebHost.HttpControllerHandler.c__DisplayClass11.b__b() at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.get_StreamContent() at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.CreateContentReadStreamAsync() at System.Net.Http.HttpContent.ReadAsStreamAsync() at System.Net.Http.HttpContentExtensions.d__0`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.ModelBinding.FormatterParameterBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Web.Http.Controllers.HttpActionBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()"
Before you start digging into the issue and lose a couple of hours(like I did), first check which version of the ‘Microsoft.AspNet.WebApi’ package you have installed.
Is it version 5.1.0.?
Don’t look any further, there is a bug inside version 5.1.0. that is causing this issue. So don’t waist more time and just update to Microsoft.AspNet.WebApi version 5.1.1 where the issue is fixed…