Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Initialize Webview2 in WPF Application work for windows user authentication

Initialize Webview2 in WPF Application work for windows user authentication

Scheduled Pinned Locked Moved WPF
wpfdebugginghelpcsharpasp-net
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aditi Arora 2021
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • A Aditi Arora 2021

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      In 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups