{"record":{"id":"e1fdcf2186c50f2e","repo":"dotnet/wpf","slug":"sr-mustnotcallsetter-xaslmember","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/XaslMember.cs","lineNumber":73,"sourceCode":"\n        [DefaultValue(true)]\n        new public bool IsBrowsable\n        {\n            get { return IsBrowsableCore; }\n            set { IsBrowsableCore = value; }\n        }\n\n        [DefaultValue(false)]\n        new public bool IsObsolete\n        {\n            get { return IsObsoleteCore; }\n            set { IsObsoleteCore = value; }\n        }\n\n        new public XamlType DeclaringType\n        {\n            get { return DeclaringTypeCore; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        // Should the default be \"x:String\"?\n        // We don't currently have a type converter to support: <XaslProperty Name=\"blah\" Type=\"x:String\" />\n        [TypeConverter(typeof(XaslTypeReferenceConverter))]\n        new public XamlType Type\n        {\n            get { return TypeCore; }\n            set { TypeCore = value; }\n        }\n\n        [DefaultValue(null)]\n        new public XamlTextSyntax TextSyntax\n        {\n            get { return TextSyntaxCore; }\n            set { TextSyntaxCore = value; }\n        }\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XaslMember.cs#L55-L91","documentation":"XaslMember (a legacy internal XAML member type) declares `new public XamlType DeclaringType` whose setter unconditionally throws InvalidOperationException('MustNotCallSetter'). The property is read-only in spirit — declaring type is fixed at construction — and mutating it through the shadowing setter is explicitly disallowed by the base-member contract.","triggerScenarios":"Assigning to DeclaringType on a XaslMember instance, e.g. myXaslMember.DeclaringType = someXamlType; — typically code written against the base XamlMember API surface that assumes the setter exists and works.","commonSituations":"Migration or tooling code that re-parents members between types at runtime; generic reflection/serialization code that sets properties via PropertyInfo.SetValue; porting older code that used a mutable DeclaringType on a different member implementation.","solutions":["Set the declaring type at construction time (constructor argument) rather than via the property.","Remove the mutation — a member's declaring type is fixed identity; create a new XaslMember bound to the correct type instead.","Catch InvalidOperationException if assignment comes from generic property-setting code and skip that property."],"exampleFix":"// before\nmember.DeclaringType = newType;\n// after\nvar rebuilt = new XaslMember(member.Name, newType);","handlingStrategy":"try-catch","validationCode":"// DeclaringType has no usable setter; never assign it.\nbool isMutable = typeof(XamlMember).GetProperty(\"DeclaringType\")!.CanWrite; // false by design","typeGuard":"static bool CanSetDeclaringType(object m) => m is not XaslMember;","tryCatchPattern":"try { prop.SetValue(member, newType); } catch (InvalidOperationException) { /* read-only member property */ }","preventionTips":["Treat DeclaringType as immutable on all XamlMember implementations.","Create a new member instance bound to the correct declaring type instead of mutating.","Skip DeclaringType in generic property-copy/serialization loops.","Update code still targeting the legacy Xasl API to the standard XamlMember."],"tags":["xaml","invalidoperation","read-only-property","api-misuse"],"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"}