Chaos.BlazorAnalyzers 0.1.3

dotnet add package Chaos.BlazorAnalyzers --version 0.1.3
                    
NuGet\Install-Package Chaos.BlazorAnalyzers -Version 0.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chaos.BlazorAnalyzers" Version="0.1.3">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Chaos.BlazorAnalyzers" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Chaos.BlazorAnalyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Chaos.BlazorAnalyzers --version 0.1.3
                    
#r "nuget: Chaos.BlazorAnalyzers, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Chaos.BlazorAnalyzers@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Chaos.BlazorAnalyzers&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Chaos.BlazorAnalyzers&version=0.1.3
                    
Install as a Cake Tool

Chaos.BlazorAnalyzers

Roslyn analyzers and diagnostic suppressors for Blazor.

Blazor assigns a lot of state after a component is constructed — injected services, @ref captures, values set in lifecycle methods. The C# compiler cannot see that, so it reports nullability warnings for code that is actually correct. This package suppresses those, and reports Blazor-specific defects the compiler and the .NET analyzers do not catch.

Installation

dotnet add package Chaos.BlazorAnalyzers

The package is a development dependency: it contributes no runtime reference and nothing ships with your application.

Suppressions

All three suppress CS8618 ("non-nullable member must contain a non-null value when exiting constructor") on types deriving from ComponentBase.

ID Suppressed when
KOS8001 The member is assigned in OnInitialized or OnInitializedAsync.
KOS8002 The member is a property marked [Inject], so DI assigns it.
KOS8003 The member is captured by an @ref, so the renderer assigns it.

Members marked [Parameter] or [CascadingParameter] are deliberately not suppressed: the framework does not guarantee they are supplied.

All three work whether or not the component declares a constructor. A component that declares one makes the compiler report every member's CS8618 against the constructor rather than against the member, and each rule resolves the member it belongs to.

Analyzers

ID Severity Description
KOS2001 Warning A component assigns an IJSObjectReference or DotNetObjectReference and never disposes it.

Configuration

Every rule is configured through .editorconfig like any other diagnostic. Suppressions are switched off the same way, which re-enables the underlying compiler warning:

# turn a suppression off, so CS8618 is reported again for @ref captures
dotnet_diagnostic.KOS8003.severity = none

# escalate an analyzer rule
dotnet_diagnostic.KOS2001.severity = error

Requirements

The analyzers target netstandard2.0 and require Roslyn 3.11 or newer, so every currently supported .NET SDK works. The floor is set by the ReSharper and Rider inspection engine, which loads no analyzer built against a newer Roslyn — building against 3.11 means dotnet jb inspectcode reports these rules too. They only activate in compilations that reference ASP.NET Core Blazor; in any other project they report nothing.

License

MIT. See LICENSE.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.3 160 9/2/2026
0.1.2 100 9/2/2026
0.1.1 88 9/1/2026