Repository navigation
Description
Scenario contact: @ilonatommy
Scenario
A component that reads the signed-in user once keeps showing the old user after sign-in or sign-out, because it never asked to be told when that changes. The symptom appears far from the cause: stale names, stale roles, and content shown to the wrong person. This validates that the build now warns about it, and that following the advice actually fixes the behavior.
Minimum build
.NET 11 Preview 7 or later.
Configurations to cover
- Blazor Web App
- Static SSR
- Interactive Server
- Interactive WebAssembly
- Interactive Auto
- Standalone WebAssembly
- Hybrid (MAUI)
These diagnostics are produced by the compiler, so they do not vary by render mode. The configuration below is the one needed to reproduce the runtime behavior the warning predicts, not a matrix to work through.
Also exercise
- Published output
- An existing .NET 10 app upgraded to .NET 11
- Trimming or ahead-of-time compilation
- More than one server instance, or a proxy in front
- Hot Reload
- An IDE as well as the command line
- Container
Setup
The app needs authentication that you can sign in and out of while it is running, so that the signed-in user genuinely changes without a full reload.
The diagnostic this scenario covers is:
| Id | Title | Code fix |
|---|---|---|
BL0013 |
AuthenticationStateProvider.GetAuthenticationStateAsync used without subscribing to AuthenticationStateChanged |
No |
What to build
Two places that read the signed-in user, because the reported problem covers both:
- A component that calls
GetAuthenticationStateAsynconce when it starts, stores the user in a field, and shows the name and roles, without subscribing toAuthenticationStateChanged. - A DI service that does the same: injects
AuthenticationStateProvider, caches the resulting user in a field, and hands it out to whatever asks. Register it as scoped and call it from a page.
Put <AuthorizeView> and <CascadingAuthenticationState> alongside them. Those two subscribe internally, so they keep up with changes and give you a live comparison on the same page.
Add a component that subscribes properly and unsubscribes on disposal, so a correct version sits next to the broken ones.
Things to try
- Building at the command line and in an IDE, and reading the messages that appear.
- Signing in and out while the page is open, without reloading the browser.
- Comparing what the component, the service and the
<AuthorizeView>show at the same moment. - Subscribing to
AuthenticationStateChangedin both the component and the service, then repeating the sign-in and sign-out test. - The correctly written component, to confirm it produces no warning.
- Reading the state from a cascading parameter instead, to see whether that is flagged.
- Navigating away from the page and back after signing in as a different user.
Expected behavior
The problem is reported at build time in both a component and a service, and subscribing fixes the runtime behavior the warning predicted.
Must hold
- Both the component and the service produce a
BL0013warning at the correct line. The service matters: a cached user in a long-lived service is the case the report called out alongside components. - Before subscribing, both still show the previous user after signing in or out, while
<AuthorizeView>on the same page shows the new one. - After subscribing, both track the signed-in user without a reload.
- The correctly written component produces no
BL0013warning, and neither does<AuthorizeView>or<CascadingAuthenticationState>. - The warning appears both at the command line and in the IDE, at the same line.
Expected differences between configurations
- None. The warning is produced at compile time and is identical in every configuration.
Documentation to use
What to report
Report results using the format described in the validation testing manual. Include link to a repository with the test app.
Note
Disclaimer: This validation scenario may have been written with AI assistance and may contain errors. It is a testing aid, not an official specification of intended behavior or security guarantees. Its expectations alone do not establish a bug or vulnerability. Verify suspected issues independently against official documentation and reproducible product behavior before reporting them.
Activity
irfanajaffer commentedon Aug 25, 2026
Test report
11.0.100-preview.7.26381.103Checks
GetAuthenticationStateAsynconce without subscribing producesBL0013StaleUserBadgeproducesBL0013at the generated Razor call siteBL0013CachedUserServiceproducesBL0013atServices/CachedUserService.cs(6,21)AuthorizeViewshow the current user and rolesBL0013warningLiveUserBadge,LiveCachedUserService,CascadingUserBadge,AuthorizeView, orCascadingAuthenticationStateThe command-line rebuild succeeded with exactly 2
BL0013warnings and 0 errors. The warnings identifyCachedUserServiceand the generated Razor call site forStaleUserBadge. No other compiler warnings were reported.Additional coverage
StaleUserBadgeis recreated with the current user; scopedCachedUserServicekeeps its original user; live consumers show current stateStaleUserBadgebecomes stale again; live consumers updateThe Alice, Bob, and sign-out screenshots are independent navigation/recreation captures, not a continuous sequence. The continuous sequence was tested separately without navigation.
Evidence: command-line build, Visual Studio Error List, initial state, Alice, Bob, sign-out, navigation return, and fixed build.
The zero-warning build can be reproduced with the preserved files under
evidence/fixed-source:Problems
None.
Documentation
The ASP.NET Core Blazor authentication state documentation describes consuming authentication state through a cascading parameter and reacting to
AuthenticationStateChanged. It does not currently mention diagnostic IDBL0013.