I'm trying to migrate a WinForms app to a more modern UI framework and I thought a Blazor WinForms hybrid app would be a good way to start. I added a reference to the Blazor WebView WinForms control into my WinForms app, and created the default Razor component library project with a Component1.razor component with this content:
<div class="my-component">
This component is defined in the <strong>MyApp.UI.Blazor</strong> library.
</div>
However when I try to add this code to populate the WebView:
var services = new ServiceCollection();
services.AddWindowsFormsBlazorWebView();
blazorWebView1.HostPage = "wwwroot\\index.html";
blazorWebView1.Services = services.BuildServiceProvider();
blazorWebView1.RootComponents.Add<Component1>("#app");
I get a compile error on the reference to Component1, even when I import it and eliminate the error in Visual Studio's error window:
error CS0246: The type or namespace name 'Component1' could not be found (are you missing a using directive or an assembly reference?)
Why would I get an error on compilation when Visual Studio reports no errors in the error window? How can I eliminate the compile error and reference the Component1 component properly so I can run the app and see it in the WebView?
Updating to Visual Studio version 17.9.0 fixed this for me!