Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 2.08 KB

File metadata and controls

34 lines (24 loc) · 2.08 KB
title BL0007: Component parameter '{0}' should be auto property
description Learn about analysis rule BL0007: Component parameter '{0}' should be auto property
author guardrex
monikerRange >= aspnetcore-3.1
ms.author riande
ms.date 04/07/2025
uid diagnostics/bl0007

BL0007: Component parameter '{0}' should be auto property

Value
Rule ID BL0007
Category Usage
Fix is breaking or non-breaking Non-breaking

Cause

A component parameter, which is a public C# property of a component class with the [Parameter] attribute, isn't an automatically-implemented property (auto property).

Rule description

A component parameter is a framework-managed communication channel between a parent and a child component. Developers shouldn't read or write to the parameter in a get (getter) or set (setter) accessor, either from inside or outside the component.

Possible side effects of interacting directly with a component parameter include infinite rendering loops, unexpected extra renderings, and parameter value overwrites.

How to fix violations

Implement the component parameter as an auto property and override xref:Microsoft.AspNetCore.Components.ComponentBase.OnParametersSet%2A or xref:Microsoft.AspNetCore.Components.ComponentBase.OnParametersSetAsync%2A in the component class to read or transform the parameter's value. For more information, see the OnParametersSet{Async} lifecycle method.

When to suppress warnings

Do not suppress a warning from this rule.