Back to Aspnetcore

BL0001: Component parameter should have public setters

aspnetcore/diagnostics/bl0001.md

latest1.4 KB
Original Source

BL0001: Component parameter should have public setters

Value
Rule IDBL0001
CategoryUsage
Fix is breaking or non-breakingBreaking

Cause

A property on a type deriving from xref:Microsoft.AspNetCore.Components.ComponentBase annotated with [Parameter] has a missing or non-public setters.

Rule description

Component parameters are required to have publicly accessible setters to allow the framework to assign values. All of the parameter declarations in the following example result in this diagnostic.

razor
@code
{
    [Parameter] int Parameter1 { get; set; }

    [Parameter] public int Parameter2 { get; }

    [Parameter] public int Parameter3 { get; private set; }
}

How to fix violations

  • Make the property and its setter public.
razor
@code
{
    [Parameter] public int Parameter1 { get; set; }

    [Parameter] public int Parameter2 { get; set; }

    [Parameter] public int Parameter3 { get; set; }
}

When to suppress warnings

Do not suppress a warning from this rule.