'GetAuthenticationStateAsync was called before SetAuthenticationState.'
See original GitHub issueDescribe the bug
GetAuthenticationStateAsync throws an InvalidOperationException with the message:
'GetAuthenticationStateAsync was called before SetAuthenticationState.'
I do not know if this is an actual bug or just a lack of documentation on its correct use.
To Reproduce
Inject a ServerAuthenticationStateProvider
into a page. Then call 'GetAuthenticationStateAsync
in any of its async-events.
Further technical details
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Exception 'GetAuthenticationStateAsync was called before ...
Describe the bug In my Blazor Server app, exactly as described in this bug report, 'GetAuthenticationStateAsync was called before SetAuthenticationState.
Read more >Error "GetAuthenticationStateAsync was called before ...
GetAuthenticationStateAsync () to call GetAuthenticationStateAsync before SetAuthenticationState. So the error will accour.
Read more >GetAuthenticationStateAsync was Called before ...
Error Message. GetAuthenticationStateAsync was called before SetAuthenticationState. Cause\Possible Cause(s). The Telerik Reporting REST Service is recommended ...
Read more >How to fix "GetAuthenticationStateAsync was called before ...
Now getting the error: GetAuthenticationStateAsync was called before SetAuthenticationState. at Microsoft.AspNetCore.Components.Server.
Read more >What is Blazor? A Tutorial on Building Web Apps with ...
... would need this as AddScoped which comes back with an error of : 'GetAuthenticationStateAsync was called before SetAuthenticationState.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Much like @eddiepaz , i’m still exeriencing the same issue. i think for me it’s because i’m using custom Middleware and utilizing IServiceProvider with CreateScope to created a Scoped instance of my User provider.
the error can be demonstrated with the following (serviceProvider is an injected IServiceProvider):
This is the problem. Don’t do that, because you’ll just receive an uninitialized instance.
You need to use the instance provided by the framework, which has been initialized. To get that, inject an
AuthenticationStateProvider
instead ofServerAuthenticationStateProvider
.For anyone else posting here, your issues may be different, since maybe you were not trying to inject
ServerAuthenticationStateProvider
. If you still have trouble, could you please post a separate issue with repro steps for your scenario? Thanks!