Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DpiAware and DpiUnaware webView2 instance sharing userDataFolder -> Exception: The group or resource is not in the correct state to perform the requested operation #899

Closed
Walkaa opened this issue Feb 5, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Walkaa
Copy link

Walkaa commented Feb 5, 2021

We have multiple applications with WebView2 instances across different processes, sharing the same userDataFolder.
Sometimes i got an System.Runtime.InteropServices.COMException while initalizing WebView2 while another one is runing:

"The group or resource is not in the correct state to perform the requested operation"

ExceptionSource:
Microsoft.Web.WebView2.Core.dll!Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateCoreWebView2ControllerAsync(System.IntPtr ParentWindow) Unknown

The environment options, WebView2 versions on all instances are exactly the same.

After hours of debugging I finally figured out what the problem is:
One winforms process is declared as dpiAware in the App.config, the other is not.

This seems to lead to different WebView2Environments, causing the second initialization to crash.

Version
Happens in newest SDK (including prerelease) and up to date runtime.
Framework: WinForms
OS: Windows 10

Repro Steps

  • Create two Winforms App with WebView2 controls.
  • Use the same userDataFolder in both apps.
  • Declare on process as DPIAware via App.config
  • Start both applications
    --> Second App will not be able to initalize WebView2

App.config code snippet
<System.Windows.Forms.ApplicationConfigurationSection> <add key="DpiAwareness" value="true"/> </System.Windows.Forms.ApplicationConfigurationSection>

Final words
Maybe this problem is not solvable because the environment just is different. But there should be at least an exception telling me the problem and the documentation has to be updated.

Thanks! :-)

@Walkaa Walkaa added the bug Something isn't working label Feb 5, 2021
@Walkaa Walkaa changed the title DpiAware and NonDpi aware webView2 instance with same userDataFolder -> Exception The group or resource is not in the correct state to perform the requested operation DpiAware and DpiUnaware webView2 instance with same userDataFolder -> Exception The group or resource is not in the correct state to perform the requested operation Feb 5, 2021
@Walkaa Walkaa changed the title DpiAware and DpiUnaware webView2 instance with same userDataFolder -> Exception The group or resource is not in the correct state to perform the requested operation DpiAware and DpiUnaware webView2 instance sharing userDataFolder -> Exception The group or resource is not in the correct state to perform the requested operation Feb 5, 2021
@Walkaa Walkaa changed the title DpiAware and DpiUnaware webView2 instance sharing userDataFolder -> Exception The group or resource is not in the correct state to perform the requested operation DpiAware and DpiUnaware webView2 instance sharing userDataFolder -> Exception: The group or resource is not in the correct state to perform the requested operation Feb 5, 2021
@lucapivato
Copy link

@Walkaa Thank you!!! Just spent 4 hours debugging this. You saved me many more. :)

@bradp0721
Copy link
Member

This behavior is currently by design. The user data folder is associated with a WebView2 browser process (1:1 mapping between user data folders and WebView2 browser processes). The Windows OS does not allow us to parent the HWND from the browser process to an HWND in the app process unless the DPI awareness values match. This issue is similar to #985.

We are working on removing that cross process SetParent dependency which would allow you to create two WebViews with the same user data folder from apps with different DPI Awarenesses. But this will come some time in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants
@lucapivato @bradp0721 @Walkaa and others