dotnet/aspnetcore · error · InvalidOperationException
Unable to set property '{parameterName}' on object of type '
Error message
Unable to set property '{parameterName}' on object of type '{target.GetType().FullName}'. The error was: {ex.Message} What it means
Thrown by ComponentProperties.SetProperty which wraps any exception raised by PropertySetter.SetValue while applying a parameter value to a component. The inner exception (type mismatch, invalid cast, custom setter logic throwing) is appended to the message. This is a catch-all surfacing failures during parameter assignment.
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 294cab2f9b)
Solutions
- Inspect the inner exception (the original exception is wrapped and its message appended) to find the real cause.
- Ensure the supplied value's type matches the parameter's declared type.
- Fix any logic in the property setter that throws unexpectedly.
- Add input validation/conversion before binding the value.
Example fix
// before
<Counter Count="not-a-number" />
// after
<Counter Count="@count" /> // @code { private int count = 0; } Defensive patterns
Strategy: try-catch
Validate before calling
// Validate that a value is assignable to a parameter before rendering/binding.
static bool CanAssign(Type parameterType, object? value)
=> value is null
? !parameterType.IsValueType || Nullable.GetUnderlyingType(parameterType) is not null
: parameterType.IsAssignableFrom(value.GetType()); Type guard
static bool IsAssignable<TParam>(object? value) => value is TParam;
Try / catch
try
{
// parameter binding happens inside the framework; catch at the render/call boundary
await component.InvokeAsync(...);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Unable to set property"))
{
logger.LogError(ex.InnerException, "Parameter set failed: {Msg}", ex.Message);
// fix the value type at the source
} Prevention
- Match the bound value's type to the parameter's declared type exactly.
- Watch nullable vs non-nullable value-type mismatches.
- Inspect InnerException for the real cause when this wraps a setter failure.
- Validate/conversion complex objects before binding.
When it happens
Trigger: Passing a value whose runtime type is incompatible with the declared parameter type; a parameter setter whose custom logic throws; a null passed to a non-nullable value-type parameter.
Common situations: Binding a string to an int parameter; nullable/non-nullable mismatches; complex object deserialization type drift; a setter that performs validation and throws on bad input.
Related errors
- Object of type '{targetType.FullName}' has a property matchi
- Object of type '{targetType.FullName}' does not have a prope
- The property '{propertyInfo.Name}' on component type '{targe
- The type '{targetType.FullName}' declares a parameter matchi
- The property '{parameterName}' on component type '{targetTyp
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/7f331b43659ea927.
Report an issue: GitHub.