Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinUI WebView2 causes crash with HTML input file while debugging after 30 seconds #3551

Open
Eilon opened this issue Jun 8, 2023 · 14 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@Eilon
Copy link

Eilon commented Jun 8, 2023

Description

A WinUI app with WebView2 that hosts HTML with an <input type="file" ... /> element will cause the app to crash and not able to debug it.

Version
SDK:
Runtime:
Framework:
OS:

Repro Steps

  1. Create new WinUI3 Packaged app
  2. Change the main XAML to be <WebView2 Source="https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_file"></WebView2> (and remove any other code from the CS file that isn't relevant)
  3. Run the app from VS with the debugger (press F5)
  4. In the app click the "Choose file" in the loaded HTML page
  5. Don't pick any files. Just wait a minute or two.

Result: The app will crash and you cannot debug it. If you try to debug it, you get all kinds of weird exceptions from VS itself (and it weirdly loads in Dark Mode... no idea why).

Expected: No crash.

Screenshots

image

Additional context

This does not repro in these similar scenarios:

  • WinUI app run without the debugger doesn't crash
  • WinUI app run from Start Menu doesn't crash
  • WPF + WebView2 doesn't crash

AB#44977210

@Eilon Eilon added the bug Something isn't working label Jun 8, 2023
@champnic champnic changed the title WinUI WebView2 causes crash with HTML input file while debugging WinUI WebView2 causes crash with HTML input file while debugging after 30 seconds Jun 8, 2023
@champnic
Copy link
Member

champnic commented Jun 8, 2023

Thanks for the bug report @Eilon. Looks like the workaround we had to do for opening the FileDialog is causing a potential re-entrancy issue that is being flagged when debugging with a _DebugBreak() and this debug output message:
"Running a message loop synchronously in an event handler in Webview can cause reentrancy issue. Please refer to https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model#re-entrancy for more information about threading model in WebView2 and how to enable native code debugging for this scenario.
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in WinUI3App1.exe."

The nested loop timer looks to be 30 seconds, which is why we see this after keeping the dialog open for a bit.

I've opened this bug on our backlog to take a look.

@champnic champnic added the tracked We are tracking this work internally. label Jun 8, 2023
@champnic champnic self-assigned this Jun 8, 2023
@CaseAlexander
Copy link

If there's any debugging information or testing needed, please let me know and my team and I will help.
We're severely impacted by this issue at the moment. Developing a Maui-Blazor and a Blazor-Server application where the client will be selecting and uploading many files. Our debug development sessions suffer frequent crashes because of this issue. Having to restart the application frequently is adding many minutes to the fix/build/test cycle.

@daghsentinel
Copy link

daghsentinel commented Sep 24, 2023

I am experiencing this too, also developing Blazor hybrid apps. Issue is also present when using .NET 8 RC1

@NJullienSweet
Copy link

NJullienSweet commented Sep 27, 2023

Hello @champnic
Do you have any news about this issue? Currently with a MAUI+Blazor app, you can't drag and drop files because there is this issue: #2805
And you also can't select a file because of this one.

To sum up, there is no way to let the user choose a file in a conventional way, making MAUI+Blazor unusable at the moment.

If you need any help to reproduce or any other thing, please feel free to ping me, I'll gladly help.
For now, my team and I are stuck and the development has been halted.

@fairjm
Copy link

fairjm commented Nov 20, 2023

@NJullienSweet hi if you use maui maybe you can choose to use FilePicker.
here is my code exmaple:

<MudFab Size="Size.Small"
        HtmlTag="label"
        Color="Color.Secondary"
        Icon="@Icons.Material.Filled.Image"
        Label="Load picture"
        OnClick="() => PickAndShow(PickOptions.Images)"
        />

@code { ....
    public async Task PickAndShow(PickOptions options)
    {
        try
        {
            var result = await FilePicker.Default.PickAsync(options);
            if (result != null)
            {
                await using var stream = await result.OpenReadAsync();
                var dotnetImageStream = new DotNetStreamReference(stream);
                _objUrl = await JS.InvokeAsync<string>("createObjectURL", dotnetImageStream);
            }
            return;
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
    }
}

@Cfun1
Copy link

Cfun1 commented Dec 17, 2023

Hi @champnic is there any update on this issue ?

@fairjm you should mention that in order to work with your example one should add a dependency to MudBlazor.
FilePicker is one thing and MudFab (from your example) is totally different thing.

@fairjm
Copy link

fairjm commented Dec 17, 2023

Hi @champnic is there any update on this issue ?

@fairjm you should mention that in order to work with your example one should add a dependency to MudBlazor. FilePicker is one thing and MudFab (from your example) is totally different thing.

MudFab is just a button, I copy the code from my project. It doesn't matter what component/html element to use, just see the callback method.

@Cfun1
Copy link

Cfun1 commented Dec 17, 2023

@fairjm my bad I was confused, thanks. In this case also FolderPicker could be used for folders.

@Wayzware
Copy link

Wayzware commented Jan 6, 2024

@champnic is there any update on this issue?

I've been experiencing it for a while now with a winforms - blazor hybrid project using .NET 6 and now .NET 8.

@Cfun1
Copy link

Cfun1 commented Apr 26, 2024

@champnic is there any update on this? Blazor+MAUI hybrid is still unusable dotnet/maui#15224

@daghsentinel
Copy link

@Cfun1 try out the suggestion made by @fairjm. It works fine here on Blazor hybrid.

@Cfun1
Copy link

Cfun1 commented Apr 26, 2024

@daghsentinel I can't do it easily because my component is in a razor class library (project type Microsoft.NET.Sdk.Razor) which is consumed by MAUI+Blazor hybrid project.

@Conbag93
Copy link

It's been 14 months since this issue was raised, and people developing MAUI Blazor projects with file uploads are still unable to debug their applications.

This is not a niché use-case, and the suggested workaround of using the MAUI FilePicker is unsuitable if you ever want your blazor component to also be consumed in a web application.

Is there any update on this? I can't really overstate how problematic this is.

@daghsentinel
Copy link

@champnic - anything you can do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

9 participants