{"record":{"id":"7f331b43659ea927","repo":"dotnet/aspnetcore","slug":"unable-to-set-property-parametername-on-object","errorCode":null,"errorMessage":"Unable to set property '{parameterName}' on object of type '{target.GetType().FullName}'. The error was: {ex.Message}","messagePattern":"Unable to set property '(.+?)' on object of type '(.+?)'\\. The error was: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Reflection/ComponentProperties.cs","lineNumber":180,"sourceCode":"                ThrowForCaptureUnmatchedValuesConflict(targetType, writers.CaptureUnmatchedValuesPropertyName!, unmatched);\n                throw null; // Unreachable\n            }\n            else if (unmatched != null)\n            {\n                // We had some unmatched values, set the CaptureUnmatchedValues property\n                SetProperty(target, writers.CaptureUnmatchedValuesWriter, writers.CaptureUnmatchedValuesPropertyName!, unmatched);\n            }\n        }\n\n        static void SetProperty(object target, PropertySetter writer, string parameterName, object value)\n        {\n            try\n            {\n                writer.SetValue(target, value);\n            }\n            catch (Exception ex)\n            {\n                throw new InvalidOperationException(\n                    $\"Unable to set property '{parameterName}' on object of \" +\n                    $\"type '{target.GetType().FullName}'. The error was: {ex.Message}\", ex);\n            }\n        }\n    }\n\n    internal static IEnumerable<PropertyInfo> GetCandidateBindableProperties([DynamicallyAccessedMembers(Component)] Type targetType)\n        => MemberAssignment.GetPropertiesIncludingInherited(targetType, BindablePropertyFlags);\n\n    [DoesNotReturn]\n    private static void ThrowForUnknownIncomingParameterName([DynamicallyAccessedMembers(Component)] Type targetType,\n        string parameterName)\n    {\n        // We know we're going to throw by this stage, so it doesn't matter that the following\n        // reflection code will be slow. We're just trying to help developers see what they did wrong.\n        var propertyInfo = targetType.GetProperty(parameterName, BindablePropertyFlags);\n        if (propertyInfo != null)\n        {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/Reflection/ComponentProperties.cs#L162-L198","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n<Counter Count=\"not-a-number\" />\n\n// after\n<Counter Count=\"@count\" /> // @code { private int count = 0; }","handlingStrategy":"try-catch","validationCode":"// Validate that a value is assignable to a parameter before rendering/binding.\nstatic bool CanAssign(Type parameterType, object? value)\n    => value is null\n        ? !parameterType.IsValueType || Nullable.GetUnderlyingType(parameterType) is not null\n        : parameterType.IsAssignableFrom(value.GetType());","typeGuard":"static bool IsAssignable<TParam>(object? value) => value is TParam;","tryCatchPattern":"try\n{\n    // parameter binding happens inside the framework; catch at the render/call boundary\n    await component.InvokeAsync(...);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unable to set property\"))\n{\n    logger.LogError(ex.InnerException, \"Parameter set failed: {Msg}\", ex.Message);\n    // fix the value type at the source\n}","preventionTips":["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."],"tags":["blazor","parameters","reflection","type-mismatch","rendering"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}