Scenario: dotnet/aspnetcore #68490
Manual: dotnet/aspnetcore #68479
.NET SDK 11.0.100-preview.7.26381.103
The scenario requires .NET 11 Preview 7 or later.
BlazorLoopClosureDemo/ and BlazorLoopClosureDemo.Client/ contain a Blazor Web App using Interactive Server rendering for the validation pages.
Start at /samples/bl0014 to access the complete sample set.
| Page | Route | Purpose |
|---|---|---|
@onclick lambda |
/samples/bl0014/flagged-onclick |
Captures the for iterator in a click handler |
| Lambda with event args | /samples/bl0014/flagged-args |
Captures the iterator alongside event arguments |
@bind indexer |
/samples/bl0014/flagged-bind |
Uses the iterator as a two-way binding index |
Child EventCallback |
/samples/bl0014/flagged-eventcallback |
Captures the iterator in a child callback |
| Child content | /samples/bl0014/flagged-childcontent |
Renders the iterator inside ChildContent |
| Page | Route | Purpose |
|---|---|---|
| Copied local | /samples/bl0014/safe-copied-local |
Copies the iterator before capturing it |
foreach over a list |
/samples/bl0014/safe-foreach |
Uses a foreach iteration variable |
foreach over Enumerable.Range |
/samples/bl0014/safe-range |
Uses a range iteration variable |
| Iterator outside a closure | /samples/bl0014/safe-loop-body-only |
Reads the iterator only in the loop body |
From the repository root:
dotnet run --project BlazorLoopClosureDemo/BlazorLoopClosureDemo.csprojOpen the HTTPS URL printed in the console, then navigate to /samples/bl0014.
dotnet clean BlazorLoopClosureDemo.sln -nologo -v:minimal
dotnet build BlazorLoopClosureDemo.sln -t:Rebuild -nologo -v:minimalExpected result: the five flagged pages produce BL0014 warnings naming the captured iterator. The copied-local, foreach, Enumerable.Range, and loop-body-only pages produce no BL0014 warning.
- Blazor Web App - Interactive Server
- Visual Studio 2022 and command-line builds
- Published Release output (
dotnet publish -c Release)
The diagnostic is produced at compile time and does not vary by render mode.
- Screenshots:
Evidence/screenshots/ - Interaction recording:
Evidence/video/ - Test report:
test-report/test-report-68490.md