Object of type 'FixLab.Components.Greeting' does not have a property matching the name
'Nam'. A component tag carries an attribute that the component does not declare as a
parameter: usually a typo (here Nam for Name), a parameter that was
renamed, or an HTML attribute such as class on a component that does not accept
extra attributes. Correct the name on the tag.
If the component is meant to pass extra attributes through to its HTML element, give it a
CaptureUnmatchedValues parameter instead, but read the warning in the fix
section before you reach for it.
The error
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Object of type 'FixLab.Components.Greeting' does not have a property matching the name 'Nam'.
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
The tag on the page:
<Greeting Nam="Maria Garcia" />
and Greeting.razor, the component it names:
<p>Hello, @Name!</p>
@code {
[Parameter] public string? Name { get; set; }
}
Why it happens
The build does not catch it. With the typo in place, dotnet build reported 0
warnings and 0 errors, because Razor turns every attribute on a component tag into a named
parameter value and leaves the matching for later. That happens when the page renders:
ComponentBase.SetParametersAsync hands each name to
ComponentProperties.SetProperties, which looks for a property with that name and
a [Parameter] attribute. With no match and no catch-all parameter, it throws. The
whole page returned a 500: one bad child tag stops the entire render.
A close cousin has its own wording. When the property exists but lacks the attribute, the
message becomes Object of type 'FixLab.Components.GreetingNoAttr' has a property
matching the name 'Name', but it does not have [Parameter], [CascadingParameter], or any
other parameter-supplying attribute. Add [Parameter] to the property.
The fix
<Greeting Name="Maria Garcia" />
With the correct name the page returned 200 and rendered "Hello, Maria Garcia!". When a component really should forward extra attributes, such as a styled button or input wrapper, it declares a catch-all:
<p @attributes="AdditionalAttributes">Hello, @Name!</p>
@code {
[Parameter] public string? Name { get; set; }
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? AdditionalAttributes { get; set; }
}
Then <GreetingLoose Name="David Chen" class="lead" /> rendered
<p class="lead">Hello, David Chen!</p>. The warning: the catch-all
swallows typos too. <GreetingLoose Nam="Maria Garcia" /> rendered
<p Nam="Maria Garcia">Hello, !</p> with no error at all, the typo
turned into an HTML attribute and the greeting left blank. Use it on components whose job is
to pass attributes through, not as a way to make this error go away.
How it was reproduced
A fresh dotnet new blazor -o FixLab --interactivity Server project on .NET SDK
10.0.401 (ASP.NET Core runtime 10.0.12, no extra packages). A Greeting
component with one Name parameter was used on a static page as
<Greeting Nam="Maria Garcia" />. The project built cleanly, and a GET of
the page returned 500 with the error above. The two variants, a property without
[Parameter] and a component with CaptureUnmatchedValues, were run
in the same project.
Frequently asked
- What does 'does not have a property matching the name' mean in Blazor?
- The component tag carries an attribute that the component does not declare as a parameter. Compare the spelling with the component's [Parameter] properties; a renamed parameter or an HTML attribute like class on a component without a catch-all causes it too.
- Why doesn't the build catch a misspelled Blazor component parameter?
- Razor compiles every attribute on a component tag into a named parameter value and does not report unknown names, so the build succeeds. The check happens at runtime, when the component receives its parameters, and the page fails with a 500.
- Should I add CaptureUnmatchedValues to fix this error?
- Only if the component is meant to forward extra HTML attributes such as class or aria-label to an element. It also swallows typos: a misspelled parameter becomes an HTML attribute and the real parameter stays empty, with no error.
More decoded errors in the Fixes category. Parameters from the beginning are in Blazor Components: Build Once, Use Everywhere.