Matblazor throws an exception in my WebAssembly project in .NET 6

196 Views Asked by At

I have used Matblazor succesfully in a .Net blazor server project in .NET 5. But my new project is now a Webassembly and is running on .NET 6. I followed all the instructions in the Matblazor home page site, but I have this client side error: Could not find matBlazor.matButton.init (matbalzor was undefined)

enter image description here

1

There are 1 best solutions below

0
Ferdi Cuyar On

you should modify your program.cs like this

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

using WareHoseManagement.Client;//this is my application so you should write here yours

using MatBlazor;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.RootComponents.Add<App>("#app");

builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddMatBlazor();

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();