dotnet/aspnetcore · error · InvalidOperationException

The property '{parameterName}' on component type '{targetTyp

Error message

The property '{parameterName}' on component type '{targetType.FullName}' cannot be set explicitly because it only accepts cascading values.

What it means

Thrown by ComponentProperties.ThrowForSettingCascadingParameterWithNonCascadingValue when a parameter is cascading-only ([CascadingParameter] and not also a direct-accepting attribute) but a direct (non-cascading) value is supplied in markup. Cascading parameters are not part of the component's public API and cannot be set explicitly.

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 294cab2f9b)

Solutions

  1. Provide the value through a <CascadingValue> wrapper instead of setting the property directly.
  2. If the value must be settable directly, keep it as a [Parameter] rather than a [CascadingParameter].
  3. Review the component's declared cascading parameters and supply them via the cascading-value pipeline only.

Example fix

// before
<Child CurrentUser="@user" /> // CurrentUser is [CascadingParameter]

// after
<CascadingValue Value="@user" TValue="User">
    <Child />
</CascadingValue>
Defensive patterns

Strategy: validation

Validate before calling

// Detect cascading-only parameters so callers know not to set them directly.
static bool IsCascadingOnly(Type componentType, string name)
{
    var p = componentType.GetProperty(name,
        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase);
    if (p is null) return false;
    bool cascading = p.GetCustomAttributes().OfType<CascadingParameterAttributeBase>().Any();
    bool parameter = p.GetCustomAttribute<ParameterAttribute>() is not null;
    return cascading && !parameter;
}

Type guard

static bool ShouldUseCascadingValue(Type componentType, string name)
    => IsCascadingOnly(componentType, name);

Prevention

When it happens

Trigger: <Child MyCascadingParam="value" /> where MyCascadingParam is decorated with [CascadingParameter] only.

Common situations: Trying to pass a cascading value directly for convenience/testing; misunderstanding the difference between regular and cascading parameters; refactoring a [Parameter] into a [CascadingParameter] without updating call sites.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/1972b0a57e72f94a. Report an issue: GitHub.