{"record":{"id":"d29af14e9be01285","repo":"dotnet/wpf","slug":"sr-cantgetwriteonlyproperty","errorCode":null,"errorMessage":"SR.CantGetWriteonlyProperty","messagePattern":"SR\\.CantGetWriteonlyProperty","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs","lineNumber":57,"sourceCode":"        }\n\n        public MethodInfo UnderlyingGetter\n        {\n            get { return IsUnknown ? null : _member.Getter; }\n        }\n\n        public MethodInfo UnderlyingSetter\n        {\n            get { return IsUnknown ? null : _member.Setter; }\n        }\n\n        public virtual object GetValue(object instance)\n        {\n            ArgumentNullException.ThrowIfNull(instance);\n            ThrowIfUnknown();\n            if (UnderlyingGetter is null)\n            {\n                throw new NotSupportedException(SR.Format(SR.CantGetWriteonlyProperty, _member));\n            }\n\n            if (UnderlyingGetter.IsStatic)\n            {\n                return UnderlyingGetter.Invoke(null, new object[] { instance });\n            }\n            else\n            {\n                return UnderlyingGetter.Invoke(instance, Array.Empty<object>());\n            }\n        }\n\n        public virtual void SetValue(object instance, object value)\n        {\n            ArgumentNullException.ThrowIfNull(instance);\n            ThrowIfUnknown();\n            if (UnderlyingSetter is null)\n            {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs#L39-L75","documentation":"XamlMemberInvoker.GetValue reads the member's value via its underlying getter. When the member has no getter (write-only property or unknown accessor), NotSupportedException with SR.CantGetWriteonlyProperty (formatted with the member) is thrown, because there is no way to produce a value.","triggerScenarios":"Calling invoker.GetValue(instance) where the XamlMember wraps a write-only property (setter only, UnderlyingGetter is null); also invoked by member.UnknownInvoker paths.","commonSituations":"Generic property-walking code (dumpers, serializers, diff tools) that calls GetValue on every member without checking whether it is readable; attached properties defined with only a setter.","solutions":["Check `invoker.UnderlyingGetter is null` (or member.IsReadPublic / CanRead) before calling GetValue and skip or log instead.","Wrap in try-catch for NotSupportedException if member readability cannot be determined statically.","If read access is genuinely required, add a getter to the property or use the backing field/storage directly."],"exampleFix":"// before\nforeach (var m in type.GetAllMembers()) values[m.Name] = m.Invoker.GetValue(obj); // throws on write-only\n// after\nforeach (var m in type.GetAllMembers())\n{\n    if (m.Invoker.UnderlyingGetter is not null)\n        values[m.Name] = m.Invoker.GetValue(obj);\n}","handlingStrategy":"type-guard","validationCode":"bool canRead = member.Invoker.UnderlyingGetter is not null;","typeGuard":"static bool CanRead(XamlMember m) => m.Invoker.UnderlyingGetter is not null;","tryCatchPattern":"try { value = invoker.GetValue(instance); }\ncatch (NotSupportedException) { /* write-only member: skip */ }","preventionTips":["Check CanRead/UnderlyingGetter before any generic GetValue call","Skip members without getters in serialization/dump code","Know which attached properties are set-only in your schemas"],"tags":["wpf","system-xaml","not-supported-exception","write-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"}