Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio debugging stop immediately on file upload in mvc?

So I'm trying to get into .NET Core MVC using Visual Studio 2019 Enterprise.

I tried to follow a fairly simple example from Microsofts own documentation. After setting up the code, I have the template project that they give you with MVC. So on the "About" page I have the following controller class AboutController.cs with the method found on Microsofts website:

[HttpPost("UploadFiles")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
    long size = files.Sum(f => f.Length);
    string filePath = Path.GetTempFileName();

    if (files.Count > 0)
    {
        IFormFile file = files[0];
        if (file.Length > 0)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
        }
    }

    return View();
}

The only "big" difference is that I return the view, not an "Ok" because I'm not really interested in that. I want to modify the view I'm looking at not go to a completely new view (maybe I'm misunderstanding how MVC works?).

Now my HTML looks like this:

<form method="post" enctype="multipart/form-data" asp-controller="About" asp-action="Post">
    <div class="form-group">
        <div class="col-md-10">
            <p>Upload one image using this form:</p>
            <input type="file" name="files">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-10">
            <input type="submit" value="Upload">
        </div>
    </div>
</form>

This produces the form, also as seen in their documentation linked earlier. When I click the "Browse" button to find a picture, it works fine and when I click "Open" so I can upload it, the Visual Studio debugger stops running immediately. No error anywhere that I can see.

Any idea what causes this behaviour?

Update 1

It appears that just calling return View(); exhibits the same behaviour and Nuget says it's AspNetCore.Mvc 2.1.1

Update 2

Turns out the debugger does not work in this particular instance with the browser called "Brave" which is a chromium browser that I use (which If forgot to mention)

like image 829
OmniOwl Avatar asked Sep 20 '19 07:09

OmniOwl


People also ask

How do I force stop debugging in Visual Studio?

To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.

How do I keep debugging in Visual Studio?

In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging.


1 Answers

This behavior in specific has been attributed to a browser problem and not Visual Studio in general. As per this article and this article, this behavior was generally observed when using browsers like Brave in this case and Yandex. Sometimes even Chrome shows this behavior but it is not consistent (at least that is what I have observed).

A possible solution would be changing your browser type to use ideal browsers like Chrome, Firefox or Edge.

As pointed out in the comments for users using Brave browser:

Turning the Shields off(down) stops the crashing. You can do this by clicking the shield icon to the right of the URL.

like image 80
Rahul Sharma Avatar answered Sep 27 '22 20:09

Rahul Sharma