2

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.

J R
  • 584
  • 5
  • 13
  • 3
    This is just a guess... WebView2 probably can't create its cache folder under `C:\Program Files\Microosft Office\...`. Maybe try something from: https://stackoverflow.com/questions/62470733/set-cache-directory-for-webview2 – rfmodulator Feb 25 '21 at 22:10
  • Thanks @rfmodulator, I found the CoreWebView2CreationProperties settings in the meantime, which solved it – J R Feb 25 '21 at 22:27

1 Answers1

7

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>
J R
  • 584
  • 5
  • 13