microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.27k stars 674 forks source link

Webview2 cannot be created when a WinUI3.0 desktop app is built as partialTrust #7982

Open koenvd opened 1 year ago

koenvd commented 1 year ago

Describe the bug

This issue is probably on the border between WinUI3.0 and WindowsAppSDK but creating it here since it's related to how the app is being built.

I was trying to move away from running a win32 WinUI 3.0 desktop app full trust to running it partial trust as explained here https://nicksnettravels.builttoroam.com/windows-ui-as-partial-trust/

The app can be successfully built but upon running I can no longer create an instance of a Webview2 control.

exception_creating_webview2

I kind of get that this exception is probably expected since the app probably has to load dll"s from outside it's container to be able to instantiate a Webview2 control.

However still logging this since:

Steps to reproduce the bug

  1. Create WinUI3.0 desktop app
  2. Add Webview2 control
  3. Build the app as partial trusted

Run the app and notice an exception being thrown.

Expected behavior

Ideally no exception should be thrown, or a dedicated capability is introduced to still allow to create a Webview2 control when the app is partial trusted.

Screenshots

No response

NuGet package version

Windows App SDK 1.2.1: 1.2.221116.1

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 21H2 (22000)

IDE

Visual Studio 2022

Additional context

No response

kovdu commented 1 year ago

Maybe this https://github.com/microsoft/microsoft-ui-xaml/issues/7190 is related? And from there it looks like it might have worked in the past?

Still interested to know if this should or can work.

koenvd commented 1 year ago

I want to go through certification on the Microsoft Store and still need to add fullTrust as capability when using a Webview2 control.

So still wondering if there's a way to use a Webview2 when the app is partialTrust @bpulliam ? (Mentioning you since not sure who else I could ask this).

kovdu commented 1 year ago

This is the stack trace.

Apparently 'Window creation request failed.' exception being thrown.

'App.exe' (Win32): Loaded 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.Impl.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.1_1004.584.2120.0_x64__8wekyb3d8bbwe\Microsoft.Web.WebView2.Core.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Users\Koen\AppData\Local\Microsoft\Edge SxS\Application\112.0.1683.0\EBWebView\x64\EmbeddedBrowserWebView.dll'. 
The thread 0x164c has exited with code 0 (0x0).
'App.exe' (Win32): Loaded 'C:\Windows\System32\version.dll'. Symbols loaded.
Exception thrown at 0x00007FFCBE2D441C (KernelBase.dll) in App.exe: WinRT originate error - 0x8000FFFF : 'Window creation request failed.'.
onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFCBEC390CE: (caller: 00007FFCBEB1C59B) ReturnHr(1) tid(5210) 8007007E The specified module could not be found.
Exception thrown at 0x00007FFCBE2D441C (KernelBase.dll) in App.exe: WinRT originate error - 0x8000FFFF : 'Window creation request failed.'.
onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFCBEC390CE: (caller: 00007FFCBEB1C59B) ReturnHr(2) tid(5210) 8007007E The specified module could not be found.
'App.exe' (Win32): Loaded 'C:\Windows\System32\Windows.System.Profile.PlatformDiagnosticsAndUsageDataSettings.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Windows\System32\DiagnosticDataSettings.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Windows\System32\policymanager.dll'. Symbols loaded.
'App.exe' (Win32): Unloaded 'C:\Windows\System32\policymanager.dll'
Exception thrown at 0x00007FFCBE2D441C (KernelBase.dll) in App.exe: WinRT originate error - 0x8000FFFF : 'Catastrophic failure'.
onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFCBEC390CE: (caller: 00007FFCBEB1C59B) ReturnHr(3) tid(5210) 8007007E The specified module could not be found.
Exception thrown at 0x00007FFCBE2D441C in App.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x0000009314D7BEB0.
kovdu commented 1 year ago

Noticed I was using Canary version of Webview2 runtime but same thing happening with Stable Release version. Runtime is loaded from a different folder, same error tough.

'App.exe' (Win32): Loaded 'C:\Windows\System32\cabinet.dll'. Symbols loaded.
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
'App.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.1_1004.584.2120.0_x64__8wekyb3d8bbwe\Microsoft.Web.WebView2.Core.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Program Files (x86)\Microsoft\EdgeWebView\Application\110.0.1587.46\EBWebView\x64\EmbeddedBrowserWebView.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Windows\System32\version.dll'. Symbols loaded.
Exception thrown at 0x00007FFCBE2D441C (KernelBase.dll) in App.exe: WinRT originate error - 0x8000FFFF : 'Window creation request failed.'.
onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFCBEC390CE: (caller: 00007FFCBEB1C59B) ReturnHr(1) tid(e08) 8007007E The specified module could not be found.
Exception thrown at 0x00007FFCBE2D441C (KernelBase.dll) in App.exe: WinRT originate error - 0x8000FFFF : 'Window creation request failed.'.
onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFCBEC390CE: (caller: 00007FFCBEB1C59B) ReturnHr(2) tid(e08) 8007007E The specified module could not be found.
'App.exe' (Win32): Loaded 'C:\Windows\System32\Windows.System.Profile.PlatformDiagnosticsAndUsageDataSettings.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Windows\System32\DiagnosticDataSettings.dll'. Symbols loaded.
'App.exe' (Win32): Loaded 'C:\Windows\System32\policymanager.dll'. Symbols loaded.
'App.exe' (Win32): Unloaded 'C:\Windows\System32\policymanager.dll'
Exception thrown at 0x00007FFCBE2D441C (KernelBase.dll) in App.exe: WinRT originate error - 0x8000FFFF : 'Catastrophic failure'.
onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFCBEC390CE: (caller: 00007FFCBEB1C59B) ReturnHr(3) tid(e08) 8007007E The specified module could not be found.
Exception thrown at 0x00007FFCBE2D441C in App.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000488D37BEC0.

Exception thrown at 0x00007FFCBE2D441C in App.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000488D379A70.

Exception thrown at 0x00007FFCBE2D441C in App.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000488D37BDD0.

Exception thrown at 0x00007FFCBE2D441C in App.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Microsoft.Web.WebView2.Core.dll!00007FFBBDC46B82: ReturnHr(1) tid(e08) 8000FFFF Catastrophic failure
    Msg:[winrt::hresult_error: Catastrophic failure] 
Exception thrown at 0x00007FFCBE2D441C in App.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000488D37BF70.
eduardobragaxz commented 1 year ago

Not only when set to PartialTrust, but also if making the app single instance.

koenvd commented 1 year ago

Wondering if a fix for this is being considered @bpulliam @chigy ?

chigy commented 1 year ago

@koenvd , we currently do not have a plan to address this issue in the near future.

orosbogdan commented 6 months ago

Also facing the same issue with MAUI blazor hybrid on .NET 8, it renders a blank page when using partial trust.

dahlita commented 4 months ago

Facing the same issue as well; is there any workaround to get the webview to load? Without putting the entire app in FullTrust mode?

epsmae commented 3 months ago

Any update on that? @chigy I hope this was a joke that you won't address this issue. Don't understand why I should give an application full trust only for initializing a webview. Also not sure how I should explain that to the users of the app.

epsmae commented 1 month ago

@chigy Any update? @dahlita @orosbogdan did you find a workaround?