Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

[Question] getting Error : Unable to resolve service for type 'Blazored.LocalStorage.LocalStorageService' #76

@nssidhu

Description

@nssidhu

Please be sure to check the readme file before raising an issue.
I am trying to use Blazor storage library in Blazor Hosted WebAssembly.

public class Program
   {
       public static async Task Main(string[] args)
       {
           var builder = WebAssemblyHostBuilder.CreateDefault(args);
           builder.RootComponents.Add<App>("app");

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

          
           builder.Services.AddBlazoredLocalStorage();

           builder.Services.AddBlazoredSessionStorage();

           builder.Services.AddScoped<AppStateInfo,AppStateInfo>();
           builder.Services.AddScoped<CustomAuthenticationStateProvider>();
           builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
                 provider.GetRequiredService<CustomAuthenticationStateProvider>());
                     
           builder.Services.AddOptions();
           var host = builder.Build();
      
           await host.RunAsync();
       }
   }

Error i get is as follow
Unhandled exception rendering component: Unable to resolve service for type 'Blazored.LocalStorage.LocalStorageService' while attempting to activate 'myCustomApp.Services.CustomAuthenticationStateProvider'.
System.InvalidOperationException: Unable to resolve service for type 'Blazored.LocalStorage.LocalStorageService' while attempting to activate 'myCustomApp.CustomAuthenticationStateProvider'.

My Constructor looks like this and class is in the Blazor Client Project

public CustomAuthenticationStateProvider(Blazored.LocalStorage.LocalStorageService LocalStorage,
          Blazored.SessionStorage.SessionStorageService SessionStorage, AppStateInfo AppStateInfo, HttpClient Http)
      {
          _localStorage = LocalStorage;
          _SessionStorage = SessionStorage;
          _appStateInfo = AppStateInfo;
          _Http = Http;

      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionQuestion about this projectResolved: AnsweredThe question raised by the author has been answered

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions