Back to Aspnetcore

BL0003: Component parameter with CaptureUnmatchedValues has the wrong type

aspnetcore/diagnostics/bl0003.md

latest1.2 KB
Original Source

BL0003: Component parameter with CaptureUnmatchedValues has the wrong type

Value
Rule IDBL0003
CategoryUsage
Fix is breaking or non-breakingBreaking

Cause

A parameter on a type deriving from xref:Microsoft.AspNetCore.Components.ComponentBase annotated with xref:Microsoft.AspNetCore.Components.ParameterAttribute.CaptureUnmatchedValues= true is not assignable from Dictionary<string, object>

Rule description

Parameters annotated with CaptureUnmatchedValues = true must be able to receive a Dictionary<string, object> value.

razor
@code
{
    [Parameter(CaptureUnmatchedValues = true)] public IDictionary<string, string> Attributes { get; set; }
}

How to fix violations

Change the type of the parameter to either IDictionary<string, object> or Dictionary<string, object>

razor
@code
{
    [Parameter(CaptureUnmatchedValues = true)] public IDictionary<string, object> Attributes { get; set; }
}

When to suppress warnings

Do not suppress a warning from this rule.