ReadAsMultipartAsync Throws System.ArgumentException
<p>I have tried searching on here and Google for an answer to this but have yet to find one.  I am using what I have found to be fairly standard for .NET 4.0 upload to Web API service.  Here is the code:</p>

<pre><code>    public HttpResponseMessage Post()
    {
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }
        StringBuilder sb = new StringBuilder();

        string root = HttpContext.Current.Server.MapPath("~/App_Data");
        var provider = new MyMultipartFormDataStreamProvider(root);

        var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith&lt;HttpResponseMessage&gt;(t =&gt;
        {
            if (t.IsFaulted || t.IsCanceled)
            {
                Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
            }

            // This will give me the form field data
            foreach (var key in provider.FormData.AllKeys)
            {
                foreach (var val in provider.FormData.GetValues(key))
                {
                    sb.Append(string.Format("{0}: {1}", key, val));
                }
            }

            // This will give me any file upload data
            foreach (MultipartFileData file in provider.FileData)
            {
                sb.Append(file.Headers.ContentDisposition.FileName);
                sb.Append("Server file path: " + file.LocalFileName);
            }
            return new HttpResponseMessage()
            {
                Content = new StringContent(sb.ToString())
            };
        });
        return Request.CreateResponse(HttpStatusCode.OK);
    }
</code></pre>

<p>When I create a very basic form with a input type=file and submit it I am getting an exception thrown for files over about 800Kb.  Here is the exception:</p>

<pre><code>System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=Value does not fall within the expected range.
  Source=mscorlib
  StackTrace:
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress()
       at System.Web.HttpWorkerRequest.IsLocal()
       at System.Web.Configuration.CustomErrorsSection.CustomErrorsEnabled(HttpRequest request)
       at System.Web.HttpContextWrapper.get_IsCustomErrorEnabled()
       at System.Web.Http.WebHost.HttpControllerHandler.&lt;&gt;c__DisplayClassa.&lt;ConvertRequest&gt;b__9()
       at System.Lazy`1.CreateValue()
       at System.Lazy`1.LazyInitValue()
       at System.Lazy`1.get_Value()
       at System.Web.Http.HttpConfiguration.ShouldIncludeErrorDetail(HttpRequestMessage request)
       at System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Func`2 errorCreator)
       at System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Exception exception)
       at aocform.Controllers.ValuesController.&lt;&gt;c__DisplayClass2.&lt;Post&gt;b__1(Task`1 t) in c:\Users\fred_malone\Documents\Visual Studio 2012\Projects\aocform\aocform\Controllers\ValuesController.cs:line 30
       at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException: 
</code></pre>

<p>I check the App_Data folder and I see part of the file there. This small part is not always the same size either, like maybe it cuts off at a certain size.  </p>

<p>I have adjusted both the <code>maxRequestLength</code> and the <code>maxAllowedContentLength</code> to large numbers with no success.</p>

<p>What does this message mean and what should I be looking at to fix it? </p>

<p>Thanks.</p>
