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.