{"record":{"id":"730561b238536158","repo":"dotnet/wpf","slug":"sr-mustnotcallsetter-unknownproperty","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/UnknownProperty.cs","lineNumber":167,"sourceCode":"            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override bool IsAttachableCore\n        {\n            get { return _isAttachable; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override bool IsEventCore\n        {\n            get { return false; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override bool IsDirectiveCore\n        {\n            get { return false; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override XamlType TargetTypeCore\n        {\n            get { return null; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override AllowedMemberLocation AllowedLocationCore\n        {\n            get { return AllowedMemberLocation.Any; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n\n        protected override XamlProperty DependsOnCore\n        {\n            get { return null; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/UnknownProperty.cs#L149-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nmember.IsDirectiveCore = true; // throws\n\n// after\nclass DirectiveProperty : UnknownProperty\n{\n    protected override bool IsDirectiveCore => true;\n}","handlingStrategy":"type-guard","validationCode":"if (member is UnknownProperty) throw new InvalidOperationException(\"UnknownProperty override members are read-only\");","typeGuard":"bool IsMutableMember(XamlMember m) => m is not UnknownProperty;","tryCatchPattern":"try { member.IsDirective = flag; }\ncatch (InvalidOperationException) { /* UnknownProperty and similar sentinels are immutable; use a concrete member type */ }","preventionTips":["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"],"tags":["xaml","read-only","invalid-operation"],"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"}