I'm trying to use WebView2 in a WPF application. I read in the docs and in other posts as well, that I should call the EnsureCoreWebView2Async()
or set the Source
property in order to initialize the WebView. If I set the Source
, it loads the web page correctly, but I can't do this way, because I have the html content in memory (and it's not allowed to write to disk).
So I tried to call the initialization method:
var webView = new WebView2();
webView.NavigationCompleted += Navigation_Completed;
webView.Initialized += new EventHandler((object sender, EventArgs e) => {
webView.NavigateToString(myHtml);
});
await webView.EnsureCoreWebView2Async(null);
Running of this code is blocked by the EnsureCoreWebView2Async()
method. I can even wait for one minute, but nothing happens, it's just stuck in initialization. No exception, no error message.
I run this code on UI thread, but the same thing happened when I called this method on another thread.
Does anyone experienced this behavior? Any ideas?