dotnet/wpf · error · InvalidOperationException
SR.MustNotCallSetter
Error message
SR.MustNotCallSetter
What it means
UnknownProperty.IsDirectiveCore exposes only a getter; its setter unconditionally throws InvalidOperationException with SR.MustNotCallSetter. UnknownProperty is a read-only sentinel member representing unrecognized properties, so overriding these lookup results is not supported — it is an internal invariant against mutating the override hook.
Solutions
- Do not write to these override properties; provide values via the constructor or by overriding with your own getter-only implementation in a subclass.
- Use a different XamlProperty-derived type if you need a member that supports these flags.
- Remove reflection code that sets properties without checking for setter-guard exceptions.
Example fix
// before
member.IsDirectiveCore = true; // throws
// after
class DirectiveProperty : UnknownProperty
{
protected override bool IsDirectiveCore => true;
} Defensive patterns
Strategy: type-guard
Validate before calling
if (member is UnknownProperty) throw new InvalidOperationException("UnknownProperty override members are read-only"); Type guard
bool IsMutableMember(XamlMember m) => m is not UnknownProperty;
Try / catch
try { member.IsDirective = flag; }
catch (InvalidOperationException) { /* UnknownProperty and similar sentinels are immutable; use a concrete member type */ } Prevention
- Never write to *Core override properties on XamlMember/XamlProperty
- Treat UnknownProperty as a read-only sentinel
- Pass configuration through constructors, not setters
- Derive your own subclass when custom values are needed
When it happens
Trigger: Assigning to the protected virtual IsDirectiveCore property (directly or through a base-class setter path) on an UnknownProperty instance, e.g. from a subclass or schema component trying to set the directive flag.
Common situations: Custom XAML schema code deriving from or poking at XamlProperty overrides and attempting to initialize override properties via setters instead of constructor arguments; reflection-based tools writing to properties regardless of setter logic.
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
- Cannot remove signature from read-only file.
- Cannot set read-only property
- Image_OriginalStreamReadOnly
- InvalidOperationException(SR.Format(SR.PrefixNotInFrames…
- (no message - parameterless InvalidOperationException)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/730561b238536158.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/UnknownProperty.cs:167
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override bool IsAttachableCore
{
get { return _isAttachable; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override bool IsEventCore
{
get { return false; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override bool IsDirectiveCore
{
get { return false; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override XamlType TargetTypeCore
{
get { return null; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override AllowedMemberLocation AllowedLocationCore
{
get { return AllowedMemberLocation.Any; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override XamlProperty DependsOnCore
{
get { return null; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }View on GitHub (pinned to 81131a70a4)