Search code examples
blazorblazor-client-sideblazorise

Blazor WebAssembly Blazorise


I am trying to use the Blazorise frontend components library(https://blazorise.com/docs/start/) In section 4a I am to add the code in Program.cs;


    builder.Services.AddSingleton( new HttpClient
        {
          BaseAddress = new Uri( builder.HostEnvironment.BaseAddress )
        } );

This gives me the error: "WebAssemblyHostBuilder" does not contain a definition for HostEnvironment and not accessible extension method 'HostEnvironment' accepting a first argument of type WebAssemblyHostBuilder

Any suggestions how to fix this?

This is all of the code in Program.cs: '''

 public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.Services
              .AddBlazorise(options =>
              {
                  options.ChangeTextOnKeyPress = true;
              })
              .AddBootstrapProviders()
              .AddFontAwesomeIcons();

            builder.Services.AddSingleton(new HttpClient
            {
                BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
            });


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

            var host = builder.Build();

            host.Services
              .UseBootstrapProviders()
              .UseFontAwesomeIcons();

            await host.RunAsync();
        }
    }

''' Note: This is a Blazor WebAssembly ASP.NET Core hosted project


Solution

  • You're using an old version of the Blazor WebAssembly template...

    Please, update your Visual Studio to the latest version. Then execute the following in a command prompt: dotnet add package Microsoft.AspNetCore.Components.WebAssembly.Authentication --version 3.2.0-rc1.20223.4

    Now launch your Visual Studio, create a new Blazor WebAssembly, go to the Program file, and add the setting related to the Blazorise library...

    This should work...