{"record":{"id":"33ad55fe109964c1","repo":"dotnet/maui","slug":"the-bindableproperty-property-propertyname-is","errorCode":null,"errorMessage":"The BindableProperty \"{property.PropertyName}\" is readonly.","messagePattern":"The BindableProperty \"(.+?)\" is readonly\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableObject.cs","lineNumber":855,"sourceCode":"\t\t/// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"propertyKey\"/> is <see langword=\"null\"/>.</exception>\n\t\t/// <exception cref=\"InvalidOperationException\">Thrown when the bindable property identified by <paramref name=\"propertyKey\"/> is read-only.</exception>\n\t\t/// <exception cref=\"ArgumentException\">Thrown when the value is invalid according to the assigned logic in <see cref=\"BindableProperty.ValidateValueDelegate\"/>.</exception>\n\t\t/// <remarks>If <see cref=\"BindableProperty.CoerceValueDelegate\"/> is not assigned to, nothing will happen.</remarks>\n\t\tpublic void CoerceValue(BindablePropertyKey propertyKey)\n\t\t{\n\t\t\tif (propertyKey == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(propertyKey));\n\n\t\t\tCoerceValue(propertyKey.BindableProperty, checkAccess: false);\n\t\t}\n\n\t\tvoid CoerceValue(BindableProperty property, bool checkAccess)\n\t\t{\n\t\t\tif (property == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(property));\n\n\t\t\tif (checkAccess && property.IsReadOnly)\n\t\t\t\tthrow new InvalidOperationException($\"The BindableProperty \\\"{property.PropertyName}\\\" is readonly.\");\n\n\t\t\tBindablePropertyContext bpcontext = GetContext(property);\n\t\t\tif (bpcontext == null)\n\t\t\t\treturn;\n\n\t\t\tobject currentValue = bpcontext.Values.GetValue();\n\n\t\t\tif (property.ValidateValue != null && !property.ValidateValue(this, currentValue))\n\t\t\t\tthrow new ArgumentException($\"Value is an invalid value for {property.PropertyName}\", nameof(currentValue));\n\n\t\t\tproperty.CoerceValue?.Invoke(this, currentValue);\n\t\t}\n\n\t\t[Flags]\n\t\tinternal enum BindableContextAttributes\n\t\t{\n\t\t\tIsBeingSet = 1 << 1,\n\t\t\t//GO AWAY","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableObject.cs#L837-L873","documentation":"InvalidOperationException thrown by CoerceValue(BindableProperty, checkAccess:true) when the property is read-only. The public CoerceValue(BindableProperty) passes checkAccess:true, so attempting to coerce a read-only BindableProperty through that overload is rejected; read-only properties must be coerced via their BindablePropertyKey. The message names the offending property.","triggerScenarios":"Calling the public CoerceValue(someReadOnlyBindableProperty) on a property declared with BindableProperty.CreateReadOnly (its BindableProperty has IsReadOnly=true).","commonSituations":"Coercing a read-only property from code that only holds the BindableProperty (not the key); generic coercion utilities that do not distinguish read-only properties.","solutions":["Use the CoerceValue(BindablePropertyKey) overload for read-only properties, passing the key returned from CreateReadOnly.","Expose the key (e.g. as a protected/internal property) so external coercers can call the key-based overload.","If you control the property, decide whether it truly needs to be read-only."],"exampleFix":"// before\nobj.CoerceValue(MyControl.ReadOnlyProp); // IsReadOnly=true -> throws\n// after\nobj.CoerceValue(MyControl.ReadOnlyPropKey); // key-based overload, checkAccess=false","handlingStrategy":"type-guard","validationCode":"if (property.IsReadOnly)\n    throw new InvalidOperationException(\"Use the BindablePropertyKey overload for read-only properties.\");\nobj.CoerceValue(property);","typeGuard":"static bool IsCoerciblePublicly(Microsoft.Maui.Controls.BindableProperty p) => p is not null && !p.IsReadOnly;","tryCatchPattern":"try { obj.CoerceValue(prop); }\ncatch (InvalidOperationException) { obj.CoerceValue(propKey); }","preventionTips":["Track whether a property is read-only and keep its key accessible for coercion.","Expose keys to code that needs to coerce read-only properties."],"tags":["maui","coerce","readonly","invalidoperation","bindableproperty"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}