dotnet/wpf · error · InvalidOperationException
SR.MustNotCallSetter
Error message
SR.MustNotCallSetter
What it means
XaslMemberReference overrides NameCore and IsPublicCore with getters backed by _name/Ref; their setters throw InvalidOperationException(SR.MustNotCallSetter). The member reference's name and visibility are derived from its underlying reflection reference at construction and are immutable, so the setters are contract stubs only.
Solutions
- Do not assign Core properties; read them only
- If a different name/visibility is needed, build a new member reference with the correct underlying Ref
- Guard bulk-copy code against setters that throw
Example fix
// before memberRef.NameCore = "CorrectName"; // after var memberRef = new XaslMemberReference(ownerType, "CorrectName"); // correct at construction
Defensive patterns
Strategy: validation
Validate before calling
if (memberRef.NameCore !== desiredName) { memberRef = new XaslMemberReference(ownerType, desiredName); } // construct, don't assign Type guard
function hasName(m: XamlMember, name: string): boolean { return m.NameCore === name; } Try / catch
try { /* name-dependent logic */ } catch (InvalidOperationException ex) when (ex.Message.Contains("MustNotCallSetter")) { // rebuild the member reference with the correct name } Prevention
- Resolve the correct member name before lookup
- Treat NameCore/IsPublicCore as derived immutable data
- Fix the underlying Ref rather than the member
When it happens
Trigger: Assigning to NameCore or IsPublicCore on a XaslMemberReference instance, e.g. from schema code that resolves a reference and tries to correct its name or visibility in place.
Common situations: Custom IXamlSchemaProvider code fixing up member names after lookup; metadata transformation pipelines that mutate resolved members.
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.CantSetReadonlyProperty
- SR.MustNotCallSetter
- Animation_Invalid_DefaultValue
- Cannot remove signature from read-only file.
- Image_EncoderNoColorContext
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3c1a40ea4dc7fc67.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XaslMemberReference.cs:76
// and we do want some sort of error here if it fails.
_ref = (XaslMember)xamlMember;
}
return _ref;
}
}
public override String BoundName
{
get { return "XASL member " + _name; }
}
public override bool IsImplicit { get { return false; } }
public override bool IsUnknown { get { return false; } }
protected override String NameCore
{
get { return _name; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override bool IsPublicCore
{
get { return Ref.IsPublic; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override bool IsBrowsableCore
{
get { return Ref.IsBrowsable; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
protected override bool IsObsoleteCore
{
get { return Ref.IsObsolete; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }View on GitHub (pinned to 81131a70a4)