I'm trying to host a Blazor component in an Avalonia application using a WebView.
I have a Blazor project with the following class:
public class ServerManager{ private static WebApplication? _host; public static void RunServer(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton<WeatherForecastService>(); _host = builder.Build(); if (_host.Environment.IsDevelopment()) { _host.UseDeveloperExceptionPage(); } else { _host.UseExceptionHandler("/Error"); _host.UseHsts(); } _host.UseHttpsRedirection(); _host.UseStaticFiles(); _host.UseRouting(); _host.MapBlazorHub(); _host.MapFallbackToPage("/_Host"); _host.Start(); } public static void StopServer() { _host?.DisposeAsync(); }The main application has a reference to the Blazor project and calls RunServer on startupand StopServer on exit. The WebView address is set to https://localhost:7012.
This approach worked fine in WPF but it seems that the server is not correctly started in Avalonia. What am I missing?