dotnet/aspnetcore · error · InvalidOperationException
Unable to set property
Error message
Unable to set property '{parameterName}' on object of type '{target.GetType().FullName}'. The error was: {ex.Message} What it means
ComponentProperties.SetProperty is the inner writer that assigns a parameter value to a component property via PropertySetter.SetValue. It catches any exception thrown by the setter (type mismatch, conversion failure, invalid cast, exception thrown inside the property setter body) and re-wraps it with the parameter name and target type for diagnostics. The original exception is preserved as InnerException. This is the catch-all for failures during parameter binding.
Solutions
- Check the InnerException for the root cause (cast, type mismatch, or setter-thrown exception) and fix the value or setter accordingly.
- Ensure the value passed to the parameter matches the property's declared type; convert or validate before assignment.
- If the setter throws intentionally, either relax the validation or guard the input so the setter receives valid data.
Example fix
// before: passing wrong type to a parameter
<Counter Count="five" />
// Counter declares: [Parameter] public int Count { get; set; }
// after
<Counter Count="5" /> Defensive patterns
Strategy: try-catch
Try / catch
try
{
await component.SetParametersAsync(ParameterView.FromDictionary(dict));
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Unable to set property"))
{
// Inspect ex.InnerException for the root cause; correct the supplied value or the setter.
logger.LogError(ex.InnerException, "Parameter assignment failed");
throw;
} Prevention
- Validate parameter values against the declared type before assignment.
- Keep property setters side-effect-free or guard inputs to avoid throwing.
- Inspect the InnerException first to find the true cause.
When it happens
Trigger: Passing a value whose type is not assignable to the [Parameter] property's type. A component property setter whose body throws (e.g., validation logic in the setter). A null value assigned to a non-nullable value-type parameter. Incompatible types routed through reflection during RenderTreeBuilder operations or component instantiation.
Common situations: Mismatched parameter types in Razor markup (e.g., passing a string to an int parameter). Custom property setters with argument validation that throw ArgumentException. Generic components where the inferred type argument does not satisfy the property. Deserialization or dynamic value sources producing unexpected runtime types.
Related errors
- Object of type ' ' does not have a property matching the…
- The type ' ' declares a parameter matching the name ' '…
- Multiple properties were found on component type
- Object of type ' ' has a property matching the name ' '…
- The property ' ' on component type ' ' cannot be set…
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/7f331b43659ea927.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Components/src/Reflection/ComponentProperties.cs:180
ThrowForCaptureUnmatchedValuesConflict(targetType, writers.CaptureUnmatchedValuesPropertyName!, unmatched);
throw null; // Unreachable
}
else if (unmatched != null)
{
// We had some unmatched values, set the CaptureUnmatchedValues property
SetProperty(target, writers.CaptureUnmatchedValuesWriter, writers.CaptureUnmatchedValuesPropertyName!, unmatched);
}
}
static void SetProperty(object target, PropertySetter writer, string parameterName, object value)
{
try
{
writer.SetValue(target, value);
}
catch (Exception ex)
{
throw new InvalidOperationException(
$"Unable to set property '{parameterName}' on object of " +
$"type '{target.GetType().FullName}'. The error was: {ex.Message}", ex);
}
}
}
internal static IEnumerable<PropertyInfo> GetCandidateBindableProperties([DynamicallyAccessedMembers(Component)] Type targetType)
=> MemberAssignment.GetPropertiesIncludingInherited(targetType, BindablePropertyFlags);
[DoesNotReturn]
private static void ThrowForUnknownIncomingParameterName([DynamicallyAccessedMembers(Component)] Type targetType,
string parameterName)
{
// We know we're going to throw by this stage, so it doesn't matter that the following
// reflection code will be slow. We're just trying to help developers see what they did wrong.
var propertyInfo = targetType.GetProperty(parameterName, BindablePropertyFlags);
if (propertyInfo != null)
{View on GitHub (pinned to 3600ca084e)