Skip to content

"WebView2 was already initialized with a different CoreWebView2Environment" #1782

@Ssiws

Description

@Ssiws

Description
Since 1.0.992.28, I'm unable to use EnsureCoreWebView2Async(env), webview throws an exception when I try to set the Source property for the first time.

System.ArgumentException:
'WebView2 was already initialized with a different CoreWebView2Environment.
Check to see if the Source property was already set or EnsureCoreWebView2Async was previously called with different values.'

Version
SDK: 1.0.992.28
Runtime: 96.0.1031.0
Framework: WPF
OS: Win10 2004

Repro Steps

var webView = new Microsoft.Web.WebView2.Wpf.WebView2();
var env = CoreWebView2Environment.CreateAsync(null, null, new CoreWebView2EnvironmentOptions
{
     AllowSingleSignOnUsingOSPrimaryAccount = true
}).Result;
 webView.Loaded += async (sender, e) =>
    {
       await webView.EnsureCoreWebView2Async(env);
       webView.CoreWebView2.DownloadStarting += CoreWebView2_DownloadStarting;
       webView.CoreWebView2.NavigationStarting += webView_NavigationStarting;
       webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
       webView.Source = new Uri("https://www.microsoft.com/");
};
   mainGrid.Children.Clear();
   mainGrid.Children.Add(webView);

Screenshots

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions