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.
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:WebView2>
<wv2:WebView2.CreationProperties>
<wv2:CoreWebView2CreationProperties UserDataFolder="C:\Temp\myfolder"/>
</wv2:WebView2.CreationProperties>
</wv2:WebView2>
User contributions licensed under CC BY-SA 3.0