3

I am getting the following error whenever I try to do a simple form post in my MVC website.

Either BinaryRead, Form, Files, or InputStream was accessed before the internal storage was filled by the caller of HttpRequest.GetBufferedInputStream.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Either BinaryRead, Form, Files, or InputStream was accessed before the internal storage was filled by the caller of HttpRequest.GetBufferedInputStream.

enter image description here

My sample form and actions are pretty basic...

@using (Html.BeginForm("Create", "Form"))
{
    <div class="row action">
        <div class="row">
            First name: <input type="text" name="fname"><br>
            Last name: <input type="text" name="lname"><br>
        </div>
        <input type="submit" id="save" class="btn" value="Save"/>
        <input type="button" id="cancel" class="btn" value="Cancel"/>
     </div>
}

And my Controller action is even more basic...

[HttpPost]
    public ActionResult Create(FormCollection collection)
    {
        try
        {
            // TODO: Add insert logic here

            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }
Community
  • 1
  • 1
Codey
  • 171
  • 7
  • If you remove the `FormCollection collection` parameter does that solve the issue? – Justin Helgerson Jun 03 '15 at 19:59
  • That results in a "The resource cannot be found." 404 error. It tries going to "/Create", and it never hits my break point inside the action – Codey Jun 03 '15 at 20:07
  • Why did you put MVC4 and MVC5 in the tags? Did you try to do an upgrade or something which may have caused this? – Brad C Jun 03 '15 at 20:09
  • This is a website migration. Yes, in the migration process the website was upgraded from MVC 3.0 to MVC 5 – Codey Jun 03 '15 at 20:11
  • @Codey - Just for the sake of testing for now, instead of `FormCollection collection` can you replace it with `string test` and see if the original error you posted has gone away? I suspect your issue is related to your `FormCollection` use. – Justin Helgerson Jun 03 '15 at 20:12
  • Hi Justin. Edit: I was playing around with errors. Adding string test as a parameter yields the same error that is started with... (Either BinaryRead, Form, Files, or InputStream was accessed before the internal storage was filled by the caller of HttpRequest.GetBufferedInputStream.)... P.S. Thanks for helping! – Codey Jun 03 '15 at 20:56
  • A similar issue with web api is discussed here. http://stackoverflow.com/questions/17602845/post-error-either-binaryread-form-files-or-inputstream-was-accessed-before-t – Parthasarathy Jun 04 '15 at 21:06

1 Answers1

0

Please share your route.config file that might help solving this problem. Just in case also try removing the perimeters from Html.BeginForm() remove the name of the action and controller. As MVC has strong naming systems because of which we don't need to add that info.

if above doesn't solve your issue Share your route file.

waheed Asghar
  • 95
  • 1
  • 8