dotnet/wpf · error · InvalidOperationException
SR.Format(SR.ReadOnlyDesignerCoersionNotAllowed, Name)
Error message
SR.Format(SR.ReadOnlyDesignerCoersionNotAllowed, Name)
What it means
The DesignerCoerceValueCallback property setter throws this InvalidOperationException when the DependencyProperty is read-only. A designer-supplied coercion callback would allow mutating the value of a read-only property, which the key-based security model forbids, so the setter is blocked entirely.
Solutions
- Do not set DesignerCoerceValueCallback on read-only properties; coerce at the source that writes via the key instead
- If you own the property and need coercion, re-register it as writable or apply coercion logic inside the code that sets the value through the DependencyPropertyKey
- Only attach DesignerCoerceValueCallback to writable DPs, guarded by if (!dp.ReadOnly)
Example fix
// before
if (needsCoercion)
someDp.DesignerCoerceValueCallback = CoerceValue; // throws for read-only DPs
// after
if (needsCoercion && !someDp.ReadOnly)
someDp.DesignerCoerceValueCallback = CoerceValue;
// for read-only DPs, coerce inside the key-protected setter path instead Defensive patterns
Strategy: validation
Validate before calling
if (!dp.ReadOnly)
dp.DesignerCoerceValueCallback = CoerceValue;
else
ApplyCoercionAtWriteSite(); Type guard
static bool AcceptsDesignerCoercion(DependencyProperty dp) => !dp.ReadOnly;
Prevention
- Never attach designer callbacks to read-only DPs
- Coerce read-only values in the code that writes via the key
- Guard extension code with if (!dp.ReadOnly)
When it happens
Trigger: Assigning dp.DesignerCoerceValueCallback = callback where dp is a read-only property (registered via DependencyPropertyKey), typically from designer tooling or custom property-system extensions.
Common situations: Visual Studio designer or third-party designer extensions trying to install coercion on read-only DPs like IsMouseOver; test harnesses poking at the property-system extension points.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.Format(SR.ReadOnlyOverrideNotAllowed, Name)
- SR.PropertyNotReadOnly
- SR.ReadOnlyChangeNotAllowed
- Cannot remove signature from read-only file.
- Image_OriginalStreamReadOnly
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/eb75acc4d84aea40.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs:1125
// Covered by Synchronized by caller
return GlobalIndexCount++;
}
/// <summary>
/// This is the callback designers use to participate in the computation of property
/// values at design time. Eg. Even if the author sets Visibility to Hidden, the designer
/// wants to coerce the value to Visible at design time so that the element doesn't
/// disappear from the design surface.
/// </summary>
internal CoerceValueCallback DesignerCoerceValueCallback
{
get { return _designerCoerceValueCallback; }
set
{
if (ReadOnly)
{
throw new InvalidOperationException(SR.Format(SR.ReadOnlyDesignerCoersionNotAllowed, Name));
}
_designerCoerceValueCallback = value;
}
}
/// <summary> Standard unset value </summary>
public static readonly object UnsetValue = new NamedObject("DependencyProperty.UnsetValue");
private string _name;
private Type _propertyType;
private Type _ownerType;
private PropertyMetadata _defaultMetadata;
private ValidateValueCallback _validateValueCallback;
private DependencyPropertyKey _readOnlyKey;
[Flags]View on GitHub (pinned to 81131a70a4)