[Problem/Bug]: On some windows user accounts, setting parent of webview in some contexts results in - Exception: System.InvalidOperationException: CoreWebView2 members cannot be accessed after the WebView2 control is disposed. ---> System.Runtime.InteropServices.COMException: The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F) #4206
Description
What happened?
Hello. We have a Windows PPT Plugin that our customers use. We use the latest Webview2SDK. A subset of our users are encountering an issue where some of our webviews are not displaying.
They all have a consistent error that does not seem to match what we can see in the code. Only one of our dev computers and only one user account can replicate it.
The issue can be replicated on the same machine, with the same software as another working user account and we have tried many non-code things to resolve it.
Users that encounter this issue, will always encounter this issue with one specific webview use-case, which happens to be the most critical one. We are not using a framework or UI for this, it is a frameless window. Our other usecases that do require some UI uses WFP (but those generally work).
We have customers that have reported this on windows 8, 10, and 11 (both pro and home editions)
I will be attaching some resources for you to review for both a working user account and a non-working user account on a developer machine with mock content. Both users are administrators on the machine, and the user account with the issue was actually the first user created on the machine.
- logs from the debug console when walking through the user experience
- trace logs using the windows process trace (According to your troubleshooting guide)
- Screenshots of the webview utilities analizer for both users
Troubleshooting we have attempted
- Restarting the machine
- We have tried removing our plugin, deleting folders, and then re-installing
- Removing office 2016 and re-installing it (and deleting related folders)
- using add/remove program to reinstall webview2
- downloading webview2 manually and re-installing
- checking that the monitor, resolution, and zoom settings are the same for both user accounts
- Attempting to clear DPI settings or monitor cache settings in the registry (But unsure if this ever worked)
The code
Our project is large but in general, these are some parts of the code that are being used to both instantiate webview2 and then attempt to adjust the parent for some webview2 controllers.
We initialize webview2 - we use webview2 in more places than this, but we load up webviews for each slide and attempt to preload the content so that switching slides is seemless.
private async void InitializeWebView2()
{
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions();
Util.SetProxyServer(options);
string dataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create), "folder");
webView2Environment = await CoreWebView2Environment.CreateAsync(null, dataPath, options).ConfigureAwait(true);
independentController = await webView2Environment.CreateCoreWebView2ControllerAsync(pptHWND).ConfigureAwait(true);
controllersByURL = new Dictionary<string, CoreWebView2Controller>();
controllerQueue = new Queue<CoreWebView2Controller>();
for (int i = 0; i < CONTROLLER_COUNT; i++)
{
CoreWebView2Controller controller = await webView2Environment.CreateCoreWebView2ControllerAsync(pptHWND).ConfigureAwait(true);
controller.CoreWebView2.Settings.UserAgent = Util.GenerateWebView2UserAgent();
controller.CoreWebView2.Settings.AreDevToolsEnabled = Util.DevToolsEnabled();
string listeners = Properties.Resources.VizEventListeners;
await controller.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(listeners).ConfigureAwait(true);
controller.CoreWebView2.WebMessageReceived += HandleWebMessageReceivedEvent;
controller.CoreWebView2.NavigationCompleted += NavDone;
controllerQueue.Enqueue(controller);
}
}
When a user presents a slide we call this, and start to set the parent of our webviews to the presenter window
public void BeginSlideShow(int slideshowHWND, List<PESlide> slides, Func<bool> checkEOS)
{
foreach (CoreWebView2Controller controller in controllerQueue)
{
controller.ParentWindow = new IntPtr((int)slideshowHWND); //the debugger stops here the first time we get there, and throws an exception
}
UpdateAllSlides(slides);
}
We get a stacktrace error
Exception: System.InvalidOperationException: CoreWebView2 members cannot be accessed after the WebView2 control is disposed. ---> System.Runtime.InteropServices.COMException: The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
119.0.2151.72
SDK Version
stable
Framework
Other
Operating System
Windows 10, Windows 11, Other
OS Version
Microsoft Windows 11 Pro (10.0.22621.0))
Repro steps
Describing the Behavior
A working scenario results in the plugin working:
- We can open all UIs that depend on webviews and have them displayed properly. A
- If we look at task manager, we can see we many webview processes correctly loading a web page
- We see network traffic using fidler
- We do not see this webview exception in the logs.
A non-working scenario results in the plugin working in some cases where webviews are used
- We can open all but one UI that depends on webviews. When we encounter the error, the webview never even displays to the user. We can still use other webviews before and after through other UI
- If we look at task manager, we see webview processes that never load a page about:blank
- We see no network traffic or requests leaving PPT
- We see the webview exception in the logs.
Both accounts "SAY" according to the logs that they have the same DPI, zoom level, etc.
Repros in Edge Browser
Not Applicable
Regression
No, this never worked
Last working version (if regression)
No response
Attachments
- working-powerpnt.exe.WebView2Utilities.Report.2023-11-30-10-18-23.zip
- working-powerpnt.exe.WebView2Utilities.Report.2023-11-30-10-17-54.zip
- working-powerpnt.exe.WebView2Utilities.Report.2023-11-30-10-17-16.zip
- notworking-powerpnt.exe.WebView2Utilities.Report.2023-11-30-10-13-42.zip
- notworking-powerpnt.exe.WebView2Utilities.Report.2023-11-30-10-13-24.zip
- notworking-powerpnt.exe.WebView2Utilities.Report.2023-11-30-10-13-01.zip
- notworking-os-console-logs.txt
- working-os-consolelogs1.txt
- Traces: