{"record":{"id":"3c1a40ea4dc7fc67","repo":"dotnet/wpf","slug":"sr-mustnotcallsetter-xaslmemberreference","errorCode":null,"errorMessage":"SR.MustNotCallSetter","messagePattern":"SR\\.MustNotCallSetter","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XaslMemberReference.cs","lineNumber":76,"sourceCode":"                    // and we do want some sort of error here if it fails.\n                    _ref = (XaslMember)xamlMember;\n                }\n                return _ref;\n            }\n        }\n\n        public override String BoundName\n        {\n            get { return \"XASL member \" + _name; }\n        }\n\n        public override bool IsImplicit { get { return false; } }\n        public override bool IsUnknown { get { return false; } }\n\n        protected override String NameCore\n        {\n            get { return _name; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter);  }\n        }\n\n        protected override bool IsPublicCore\n        {\n            get { return Ref.IsPublic; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter);  }\n        }\n\n        protected override bool IsBrowsableCore\n        {\n            get { return Ref.IsBrowsable; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override bool IsObsoleteCore\n        {\n            get { return Ref.IsObsolete; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XaslMemberReference.cs#L58-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom IXamlSchemaProvider code fixing up member names after lookup; metadata transformation pipelines that mutate resolved members.","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"],"exampleFix":"// before\nmemberRef.NameCore = \"CorrectName\";\n// after\nvar memberRef = new XaslMemberReference(ownerType, \"CorrectName\"); // correct at construction","handlingStrategy":"validation","validationCode":"if (memberRef.NameCore !== desiredName) { memberRef = new XaslMemberReference(ownerType, desiredName); } // construct, don't assign","typeGuard":"function hasName(m: XamlMember, name: string): boolean { return m.NameCore === name; }","tryCatchPattern":"try { /* name-dependent logic */ } catch (InvalidOperationException ex) when (ex.Message.Contains(\"MustNotCallSetter\")) { // rebuild the member reference with the correct name }","preventionTips":["Resolve the correct member name before lookup","Treat NameCore/IsPublicCore as derived immutable data","Fix the underlying Ref rather than the member"],"tags":["wpf","system-xaml","invalid-operation","read-only-property"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}