dotnet/wpf · error · InvalidOperationException

This setter is not intended to be used directly from your…

Error message

This setter is not intended to be used directly from your code. Do not call this setter.

What it means

ClrProperty overrides XamlMember.NameCore with a get-only cached value and throws InvalidOperationException (SR.MustNotCallSetter) if anyone attempts to set NameCore. These setters exist only to satisfy the abstract base-class signature; mutation of schema metadata after construction is not supported.

Solutions

  1. Pass the correct name to the ClrProperty constructor instead of setting NameCore afterwards.
  2. Construct a new ClrProperty/XamlMember with the desired name rather than mutating the existing one.
  3. Use a mutable XamlMember subclass if post-construction mutation is genuinely needed.

Example fix

// before
prop.NameCore = "NewName"; // throws
// after
var prop = new ClrProperty("NewName", propertyInfo, declaringType, schemaContext);
Defensive patterns

Strategy: validation

Validate before calling

// guard before assigning XamlMember metadata
if (member is ClrProperty) throw new InvalidOperationException("ClrProperty metadata is immutable; recreate the member instead");

Type guard

bool IsImmutableMember(XamlMember m) => m.GetType().Name == "ClrProperty";

Try / catch

try { member.NameCore = newName; }
catch (InvalidOperationException ex) { log("XamlMember metadata setters must not be called: " + ex.Message); }

Prevention

When it happens

Trigger: Calling NameCore = value (or invoking the setter via reflection) on a ClrProperty instance, typically from custom XAML schema code that tries to rename a member after construction.

Common situations: Framework authors subclassing XamlMember/XamlProperty and trying to fix up member names post-construction; debugging tools setting properties blindly through reflection.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/bdff2bdac393c38d. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs:122

        // ----- Protected Overrides -----

        public override string BoundName
        {
            get { return Name; }
        }

        public override bool IsImplicit { get { return false; } }
        public override bool IsUnknown { get { return false; } }

        public override IList<string> GetXamlNamespaces()
        {
            return DeclaringType.GetXamlNamespaces();
        }

        protected override string NameCore
        {
            get { return _name; }
            set { throw new InvalidOperationException(SR.MustNotCallSetter); }
        }

        protected override bool IsPublicCore
        {
            get { return _isPublic; }
            set { throw new InvalidOperationException(SR.MustNotCallSetter); }
        }

        protected override bool IsBrowsableCore
        {
            get
            {
                bool ret = CheckPropertyBit(BoolPropertyBits.IsBrowsable);
                return ret;
            }
            set { throw new InvalidOperationException(SR.MustNotCallSetter); }
        }

View on GitHub (pinned to 81131a70a4)