warning BL0005: Component parameter 'Name' should not be set outside of its component. appears when code in a parent assigns a child's [Parameter] property through an @ref. Keep the value in a field of the parent, pass that field as the parameter in markup, and change the field instead.

In the test below that one change took the build from 1 Warning(s) to 0 Warning(s). The parent still renames the greeting; it does so by changing its own state, and the new value reaches the child as a parameter on the next render.

The error

...\Bl\Components\Pages\Home.razor(12,9): warning BL0005: Component parameter 'Name' should not be set outside of its component. [...\Bl\Bl.csproj]
...
    1 Warning(s)
    0 Error(s)

It is a warning, so the build succeeds. The position (12,9) points at the assignment line in the parent, not at the child.

Why it happens

The analyzer flags a write to a property marked [Parameter] from outside the component that declares it. The child here is a two-line greeting:

<p>Hello, @Name!</p>

@code {
    [Parameter]
    public string Name { get; set; } = "";
}

and the parent kept a reference to it and set the property in a click handler:

@page "/"
@rendermode InteractiveServer

<Greeting @ref="greeting" Name="Maria Garcia" />
<button @onclick="Rename">Rename</button>

@code {
    Greeting greeting = default!;

    void Rename()
    {
        greeting.Name = "David Chen";
    }
}

The warning points at the assignment in code, line 12; the markup value is not what it objects to. A build of the same parent with <Greeting @ref="greeting" />, no Name in markup, printed the same BL0005 line at (12,9).

The fix

@page "/"
@rendermode InteractiveServer

<Greeting Name="@name" />
<button @onclick="Rename">Rename</button>

@code {
    string name = "Maria Garcia";

    void Rename()
    {
        name = "David Chen";
    }
}

The @ref is gone, the parameter is bound to the parent's field, and the handler changes the field. dotnet build -nologo then reported 0 Warning(s) and 0 Error(s). The check in this post was the build; the rename was not clicked in a browser.

If the child should change the value itself, give it its own private field that it copies from the parameter, and let it change that field. This version of the child, with the fixed parent above, built with 0 Warning(s) and 0 Error(s):

<p>Hello, @current!</p>
<button @onclick="Shout">Shout</button>

@code {
    [Parameter]
    public string Name { get; set; } = "";

    string current = "";

    protected override void OnParametersSet()
    {
        current = Name;
    }

    void Shout()
    {
        current = current.ToUpperInvariant();
    }
}

How it was reproduced

A fresh project from dotnet new blazor -o Bl --interactivity Server on .NET SDK 10.0.403 (ASP.NET Core 10.0.14 runtime), with the two components above added under Components/Pages, built with dotnet build -nologo before and after the change. No package was added; the warning came with the project as created.

Frequently asked

What does BL0005 mean in Blazor?
Code outside a component assigned one of its [Parameter] properties, here through a reference captured with @ref. The build still succeeds; it is a warning.
How do I change a child component parameter from the parent in Blazor?
Keep the value in a field of the parent, pass the field in markup as the parameter, and change the field. The child receives the new value when the parent renders.
Can I ignore warning BL0005?
The build succeeds, so nothing forces you. In the test, removing the assignment in code and passing the value through a field of the parent removed the warning.

More decoded errors in the Fixes category. For how parameters and callbacks connect parent and child, see data binding and events in Blazor.