0

I've written an application that utilizes WebView2 in a Winform. It displays a local HTML file on a form. The debug version runs fine from within Visual Studio 2022. The Release version runs correctly when executed from File Explorer.

I created an installer to load the application on a separate machine. In testing the installation process, I found that the HTML page is not rendered in the installed version.

The HTML page source is downloaded to my machine from a web page. I know this is happening because I can see it in File Explorer. However, the WebView2 control on the form never renders the HTML source.

The WebView2 runtime is installed at

C:\Program Files (x86)\Microsoft\EdgeWebView\Application\109.0.1518.78

The code I use for rendering is:

string path = Path.Combine(_tempFolder, servicehtml);

try
{
  webView.CreationProperties = new 
  Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();
  webView.CreationProperties.BrowserExecutableFolder = 
   Properties.Resources.webview2_runtime_folder;

  webView.Source = new Uri(path);
}
catch (Exception excp)
{
  MessageBox.Show(excp.Message);

  WriteLog(LogType.Info, Properties.Resources.ERR_WEBVIEW2_FAILURE, new object[] 
     {excp.Message });
}

I set the BrowserExecutableFolder according to the discussion in Details about the Fixed Version runtime distribution mode

What am I missing that prevents the HTML from rendering correctly?

UPDATE:

I changed the above code to:

webView.CreationProperties = new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();
webView.CreationProperties.BrowserExecutableFolder = 
  Properties.Resources.webview2_runtime_folder;
webView.CreationProperties.UserDataFolder = _tempFolder;    //<=====

webView.Source = new Uri(path);

Adding the UserDataFolder allowed me to change where my HTML file was located.

Note: The WebView2 runtime will create an "EBWebView" subfolder at the UserDataFolder path.

rrirower
  • 4,338
  • 4
  • 27
  • 45
  • 1
    The following may be helpful: https://stackoverflow.com/a/73846538/10024425 . It' VB.NET, but should be easy to convert - most notably you need to specify the `UserDataFolder` otherwise it will attempt be created in the same location as the executable which may fail (`%ProgramFiles%` requires administrator privileges). You also need to review the [WebView2 Release Notes](https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes?tabs=dotnetcsharp) to ensure that your MS Edge version meets the requirements for the WebView2 version you're using. – Tu deschizi eu inchid Feb 12 '23 at 03:26
  • Thanks for the tip. I was able to use the info you provided to work through a solution. I've updated my post. – rrirower Feb 15 '23 at 19:49

0 Answers0