dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

Setting UserDataFolder on BlazorWebViewInitializingEventArgs in Blazor WPF application does not work #11144

Open kuba1 opened 1 year ago

kuba1 commented 1 year ago

Description

I cannot set UserDataFolder using BlazorWebViewInitializing event handler in Blazor WPF application with set to None. The folder used is still the same as .exe (app build folder).

Steps to Reproduce

  1. Create new .NET MAUI Blazor App in VS
  2. Add \<WindowsPackageType>None\</WindowsPackageType> to csproj
  3. Set x:Name="blazorWebView" for \<BlazorWebView> in MainPage.xaml
  4. Add handler for BlazorWebViewInitializing in MainPage.xaml.cs
  5. Set UserDataFolder of BlazorWebViewInitializingEventArgs
  6. Add Debug profile to run the exe
  7. Debug the application
  8. Verify that UserDataFolder property is set on BlazorWebViewInitializingEventArgs
  9. Run the application further

Expected outcome: user data for WebView2 is written to folder set on BlazorWebViewInitializingEventArgs Actual outcome: user data for WebView2 is written to the default (?) location - application folder (same as where the .exe file is)

This is a problem when installing in 'Program Files' or 'Program Files (x86)'.

Link to public reproduction project repository

https://github.com/kuba1/maui-bug

Version with bug

7.0 Release Candidate 2

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

hhhuut commented 1 year ago

+1, having the same issue with .NET MAUI Blazor (Hybrid). The existing workarounds for Blazor with Forms/WPF (such as #10772 ) don't work for the MAUI Blazor app.

SDK/Runtime Version: .NET 7.0.400 Platform: Windows Windows SDK: 10.0.22621.0

hhhuut commented 11 months ago

Until this problem gets fixed properly, there is a workaround by setting the appropriate environment variable before the webview even starts initializing, so for example in the page's constructor:

public MainPage()
{
    InitializeComponent();

    Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", "C:\\path\\to\\preferred\\folder");
}
NJullienSweet commented 9 months ago

Until this problem gets fixed properly, there is a workaround by setting the appropriate environment variable before the webview even starts initializing, so for example in the page's constructor:

public MainPage()
{
    InitializeComponent();

    Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", "C:\\path\\to\\preferred\\folder");
}

You just saved my day! No news from the dotnet devs about a fancier way to proceed?