{"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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/Reflection/ComponentProperties.cs#L162-L198","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: passing wrong type to a parameter\n<Counter Count=\"five\" />\n// Counter declares: [Parameter] public int Count { get; set; }\n\n// after\n<Counter Count=\"5\" />","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await component.SetParametersAsync(ParameterView.FromDictionary(dict));\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unable to set property\"))\n{\n    // Inspect ex.InnerException for the root cause; correct the supplied value or the setter.\n    logger.LogError(ex.InnerException, \"Parameter assignment failed\");\n    throw;\n}","preventionTips":["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."],"tags":["blazor","parameters","reflection","binding"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}