4

I get the following exception when the WebView2 application is launched by more than one user on the server: "Requested resource is in use.(Exception from HRESULT: 0x800700AA)"

The user that launched the application first can still open multiple sessions. How do we allow it to work with multiple users?

The debugger says that the issue is generated by the "EnsureCoreWebView2Async" method. This is how i created the environment:

 var env = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(userDataFolder: CacheDirectory);
 await this.EnsureCoreWebView2Async(env);
Zimo
  • 312
  • 5
  • 21
  • 1
    Different instances of `WebView2` must use different `UserDataFolder`. They can not share the same. Then you get your exception. – Poul Bak Nov 12 '21 at 22:06
  • Thanks for your answer. Are you saying that i need to create a separate thread for each? – Zimo Nov 12 '21 at 22:08
  • 1
    `CacheDirectory` must be unique to each instance. – Poul Bak Nov 12 '21 at 22:13
  • How do you explain that a user is able to run multiple instances of the application and they all share the same folder? – Zimo Nov 14 '21 at 09:53
  • It doesn't sound like its possible to have multiple users share the same user data folder. You can ask for a feature request on https://github.com/MicrosoftEdge/WebView2Feedback/issues/new/choose, however this sounds like a limitation in chromium and unlikely something that the webview2 team will be able to change. If you only need to share initial state you can make copies of a user data folder – David Risney Nov 15 '21 at 17:36
  • After digging a little bit more on the internet i found a documentation explaining how to share the UserDataFolder https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/user-data-folder – Zimo Nov 15 '21 at 17:39
  • 1
    To compare with 'real' browsers: Each user on the computer has his/her own userdatafolder. This applies to all browsers, I know. This is probably due to privacy and other issues. So `WebView2` is not special in this concern. There might be some kind of 'locking per user' in effect. – Poul Bak Nov 16 '21 at 02:22
  • I am getting the same error but only with one user. I do have the app deployed (installed) on the same computer, and there I received this error but not in the development environment. Any idea why? (DLLs seem to be present as instructed in their "deploying WebView2 apps" section) – Luchspeter Nov 16 '21 at 23:14

1 Answers1

4

The answer is in Microsoft Docs

https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/user-data-folder

We can use System.Environment.UserName as a directory name. That way it will keep the environments separate

Keep in mind that the environment directories have to be cleaned up when the application is closed or uninstalled.

Zimo
  • 312
  • 5
  • 21