You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using WebView2 in a WPF application to interact with our Identity provider service. When the navigation url host changes, I dispose the old instance and create a new instance with a different setting configured in CoreWebView2EnvironmentOptions. The user data folder and browser executable folder remain the same. When I call EnsureCoreWebView2Async I get this exception:
System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the correct state to perform the requested operation. (0x8007139F)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateCoreWebView2ControllerAsync(IntPtr ParentWindow)
at Microsoft.Web.WebView2.Wpf.WebView2.Microsoft.Web.WebView2.Wpf.IWebView2Private.InitializeController(IntPtr parent_window, CoreWebView2ControllerOptions controllerOptions)
at Microsoft.Web.WebView2.Wpf.WebView2Base.<>c__DisplayClass32_0.<<EnsureCoreWebView2Async>g__Init|0>d.MoveNext()
--- End of stack trace from previous location ---
at InitializeWebViewException.WebViewManager.<>c__DisplayClass2_0.<<CreateWebView>b__0>d.MoveNext() in C:\repos\InitializeWebViewException\WebViewManager.cs:line 43
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
135.0.3179.98
SDK Version
1.0.3179.45
Framework
WPF
Operating System
Windows 11
OS Version
10.0.26100
Repro steps
This issue can be consistently reproduced with the attached WPF project.
usingMicrosoft.Web.WebView2.Wpf;usingSystem.Windows;namespaceInitializeWebViewException{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>publicpartialclassMainWindow:Window{privatereadonlyWebViewManager_webViewManager=new();publicMainWindow(){InitializeComponent();}privatevoidButton_Navigate_Click(objectsender,RoutedEventArgse){WebViewContainer.Children.Clear();WebView2webView=_webViewManager.GetWebView(TextBox_NavigationUrl.Text);WebViewContainer.Children.Add(webView);}}}
WebViewManager.cs
usingMicrosoft.Web.WebView2.Core;usingMicrosoft.Web.WebView2.Wpf;usingSystem.IO;usingSystem.Windows;namespaceInitializeWebViewException{internalclassWebViewManager{privateWebView2?_webView;publicWebView2GetWebView(stringnavigationUrl){if(_webView==null||ShouldCreateNewWebView()){Reset();_webView=CreateWebView(navigationUrl);}// Will never happen in example codeelse_webView.CoreWebView2.Navigate(navigationUrl);return_webView;}privatestaticWebView2CreateWebView(stringnavigationUrl){WebView2webView=new();webView.Loaded+=asyncdelegate{try{stringuserDataFolder=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"WebView2");varwebViewEnvironment=awaitCoreWebView2Environment.CreateAsync(browserExecutableFolder:null,userDataFolder,newCoreWebView2EnvironmentOptions(){// Represents an environment option that changes between instancesAdditionalBrowserArguments=$"--auth-server-allowlist=\"{newUri(navigationUrl).Host}\""});awaitwebView.EnsureCoreWebView2Async(webViewEnvironment);webView.CoreWebView2.Navigate(navigationUrl);}catch(Exceptionex){MessageBox.Show($"Error creating WebView2: {ex.Message}","Error",MessageBoxButton.OK,MessageBoxImage.Error);}};returnwebView;}// Hard coded to reproduce the issueprivatestaticboolShouldCreateNewWebView()=>true;privatevoidReset(){_webView?.Dispose();_webView=null;}}}
This is a timing issue that stops happening if you put a 100 millisecond delay anywhere between the Reset() call and the await webView.EnsureCoreWebView2Async(webViewEnvironment) call.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
Don't know
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered:
What happened?
I am using WebView2 in a WPF application to interact with our Identity provider service. When the navigation url host changes, I dispose the old instance and create a new instance with a different setting configured in CoreWebView2EnvironmentOptions. The user data folder and browser executable folder remain the same. When I call EnsureCoreWebView2Async I get this exception:
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
135.0.3179.98
SDK Version
1.0.3179.45
Framework
WPF
Operating System
Windows 11
OS Version
10.0.26100
Repro steps
This issue can be consistently reproduced with the attached WPF project.
InitializeWebViewException.zip
Here is the code for the test project if that will be easier.
MainWindow.xaml
MainWindow.xaml.cs
WebViewManager.cs
This is a timing issue that stops happening if you put a 100 millisecond delay anywhere between the
Reset()
call and theawait webView.EnsureCoreWebView2Async(webViewEnvironment)
call.Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
Don't know
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered: