Opening WebView2 in WPF causes System.UnauthorizedAccessException while calling EnsureCoreWebView2Async


When opening a WPF window with a WebView2 component from a COM Office addin the following error occurs during a call to EnsureCoreWebView2Async(null). The Office application window is set as owner of the new WPF window.

System.UnauthorizedAccessException: 'Access denied (Exception HRESULT: 0x80070005(E_ACCESSDENIED))'

Interestingly, when calling the same window from a pure WPF application the window and webview2 work perfectly. Also without the WebView2 component the window works.

asked on Stack Overflow Feb 25, 2021 by J R

1 Answer


The issue is apparently related to the webview trying to create files (e.g. cache) in the wrong location, most likely the application folder. In CoreWebView2CreationProperties this behaviour can be adjusted and a different folder can be specified.

Example for use in WPF XAML:

         <wv2:CoreWebView2CreationProperties UserDataFolder="C:\Temp\myfolder"/>
answered on Stack Overflow Feb 25, 2021 by J R • edited Feb 26, 2021 by J R

User contributions licensed under CC BY-SA 3.0