When I install and try to launch my blazor app on windows server 2019 i get this error and i cant seem to work out whats missing for it. Its a simple blazor app that runs with winforms. i have tried installing the relevant .NET versions (7) along with enabling anything .NET related in features.
I think you has the same problem like I had. Your server has no Edge Browser installed and therefore has no WebView2 Engine
available.
You have the following options now:
Edge Browser
.WebView2
as part of your application, maybe together with an self-contained .NET Core app
. Then you don´t need any software installed on your server (no .NET SDK or Browser or WebView2, because your app brings everything with it).For the last bullet point, you need to add the following Code to your WinForms constructor:
public Form()
{
InitializeComponent();
Environment
.SetEnvironmentVariable("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", @".\WebView2");
Environment
.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", @".\WebView2UserData");
ServiceCollection services = new();
// From: Microsoft.Extensions.DependencyInjection
services.AddWindowsFormsBlazorWebView();
blazorWebView1.HostPage = "wwwroot/index.html";
blazorWebView1.Services = services.BuildServiceProvider();
blazorWebView1.RootComponents.Add<App>("#app");
}