dotnet/aspnetcore · error · InvalidOperationException
The property ' ' on component type ' ' cannot be set…
Error message
The property '{parameterName}' on component type '{targetType.FullName}' cannot be set explicitly because it only accepts cascading values. What it means
ThrowForSettingCascadingParameterWithNonCascadingValue fires when the framework is asked to set a property directly (as a normal parameter) but the property is annotated only with [CascadingParameter] (a CascadingParameterAttributeBase) and does not also accept direct parameters. Cascading parameters receive their values from a CascadingValue provider in the render tree, not from explicit attribute assignment, so direct assignment is rejected.
Solutions
- Supply the value via <CascadingValue Name="Theme" Value="dark"><MyComponent /></CascadingValue> instead of as a direct attribute.
- If direct assignment is desired, change the property from [CascadingParameter] to [Parameter].
- For [CascadingParameter] properties that should also accept direct values, verify whether SupplyParameterFromQuery or another dual-purpose attribute is intended.
Example fix
// before <MyComponent Theme="dark" /> // Theme is [CascadingParameter] // after <CascadingValue Name="Theme" Value="dark"> <MyComponent /> </CascadingValue>
Defensive patterns
Strategy: validation
Validate before calling
// Before passing a value, confirm the property accepts direct parameters.
var prop = typeof(MyComponent).GetProperty("Theme");
var acceptsDirect = prop?.GetCustomAttribute<ParameterAttribute>() != null;
var isCascadingOnly = prop?.GetCustomAttributes()
.OfType<CascadingParameterAttributeBase>().Any() == true && !acceptsDirect;
if (isCascadingOnly)
throw new InvalidOperationException("Use <CascadingValue> for Theme."); Prevention
- Distinguish [Parameter] (direct) from [CascadingParameter] (cascade) usage.
- Supply cascading values through <CascadingValue>, not direct attributes.
- Document on each property how it should receive its value.
When it happens
Trigger: In markup, writing <MyComponent Theme="dark" /> where Theme is declared as [CascadingParameter]. Programmatically calling SetDirectAsync or RenderTreeBuilder.AddAttribute with a value for a cascading-only parameter. Mixing up which properties are direct parameters versus cascading parameters.
Common situations: Confusing [Parameter] and [CascadingParameter] semantics; attempting to pass a value directly to what should be supplied by <CascadingValue>. Refactoring a parameter to cascading without removing direct usages. Authoring a component that expects a cascade but a consumer supplies it explicitly.
Related errors
- The property ' ' on component type ' ' cannot be set using…
- Object of type ' ' does not have a property matching the…
- The property ' ' on component type ' ' cannot be set…
- The type ' ' declares a parameter matching the name ' '…
- Unable to set property
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/1972b0a57e72f94a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Components/src/Reflection/ComponentProperties.cs:224
else
{
// This should not happen
throw new InvalidOperationException(
$"No writer was cached for the property '{propertyInfo.Name}' on type '{targetType.FullName}'.");
}
}
else
{
throw new InvalidOperationException(
$"Object of type '{targetType.FullName}' does not have a property " +
$"matching the name '{parameterName}'.");
}
}
[DoesNotReturn]
private static void ThrowForSettingCascadingParameterWithNonCascadingValue(Type targetType, string parameterName)
{
throw new InvalidOperationException(
$"The property '{parameterName}' on component type '{targetType.FullName}' cannot be set " +
$"explicitly because it only accepts cascading values.");
}
[DoesNotReturn]
private static void ThrowForSettingParameterWithCascadingValue(Type targetType, string parameterName)
{
throw new InvalidOperationException(
$"The property '{parameterName}' on component type '{targetType.FullName}' cannot be set " +
$"using a cascading value.");
}
[DoesNotReturn]
private static void ThrowForCaptureUnmatchedValuesConflict(Type targetType, string parameterName, Dictionary<string, object> unmatched)
{
throw new InvalidOperationException(
$"The property '{parameterName}' on component type '{targetType.FullName}' cannot be set explicitly " +
$"when also used to capture unmatched values. Unmatched values:" + Environment.NewLine +View on GitHub (pinned to 3600ca084e)