Initialize Webview2 in WPF Application work for windows user authentication
-
I am facing an exception while WebView initialize. It is working perfectly fine when i debug my code on VS 2019 but when i make an installer and install it on VM Windows 10 Machine it gives me an exception which i can get with help of Logs. I have added UDF as well in my client machine and install Microsoft edge runtime(124.0.2478.97) Please Suggest any one what i need to add to resolve this issue. Code Block
MainWindow.xaml.cs
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
public MainWindow()
{
InitializeComponent();
InitializeAndNavigateAsync( url);
}
public async Task InitializeAndNavigateAsync(string url)
{
await InitializeWebViewAsync();
await NavigateToUrlAsync(url);
}private async Task InitializeWebViewAsync() { try { log.Debug($"WebView2 initialize start"); await webView.EnsureCoreWebView2Async(null); log.Debug($"WebView2 initialize stop"); } catch (Exception e) { log.Debug($"WebView2 initialization failed.{e.Message}"); log.Debug($"WebView2 initialization failed.{e.StackTrace}"); } } private async Task NavigateToUrlAsync(string url) { try { log.Debug($"WebView2 NavigateToUrlAsync start"); webView.CoreWebView2.Navigate(url); log.Debug($"WebView2 NavigateToUrlAsync stop"); } catch (Exception e) { log.Debug($"WebView2 NavigateToUrlAsync failed.{e.Message}"); log.Debug($"WebView2 NavigateToUrlAsync failed.{e.StackTrace}"); } }
Exception is :
WebView2 initialization failed.Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))
2024-05-14 06:34:45.4923|DEBUG|debug|WebView2 initialization failed. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__80.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAw -
I am facing an exception while WebView initialize. It is working perfectly fine when i debug my code on VS 2019 but when i make an installer and install it on VM Windows 10 Machine it gives me an exception which i can get with help of Logs. I have added UDF as well in my client machine and install Microsoft edge runtime(124.0.2478.97) Please Suggest any one what i need to add to resolve this issue. Code Block
MainWindow.xaml.cs
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
public MainWindow()
{
InitializeComponent();
InitializeAndNavigateAsync( url);
}
public async Task InitializeAndNavigateAsync(string url)
{
await InitializeWebViewAsync();
await NavigateToUrlAsync(url);
}private async Task InitializeWebViewAsync() { try { log.Debug($"WebView2 initialize start"); await webView.EnsureCoreWebView2Async(null); log.Debug($"WebView2 initialize stop"); } catch (Exception e) { log.Debug($"WebView2 initialization failed.{e.Message}"); log.Debug($"WebView2 initialization failed.{e.StackTrace}"); } } private async Task NavigateToUrlAsync(string url) { try { log.Debug($"WebView2 NavigateToUrlAsync start"); webView.CoreWebView2.Navigate(url); log.Debug($"WebView2 NavigateToUrlAsync stop"); } catch (Exception e) { log.Debug($"WebView2 NavigateToUrlAsync failed.{e.Message}"); log.Debug($"WebView2 NavigateToUrlAsync failed.{e.StackTrace}"); } }
Exception is :
WebView2 initialization failed.Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))
2024-05-14 06:34:45.4923|DEBUG|debug|WebView2 initialization failed. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__80.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwIn your InitializeWebViewAsync method, try creating a CoreWebView2Environment object (you'll need to give it a folder path to use) and passing that to the EnsureCoreWebView2Async method.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak