{"record":{"id":"ee9702e458ded977","repo":"dotnet/wpf","slug":"cannot-get-write-only-property-0","errorCode":null,"errorMessage":"Cannot get write-only property '{0}'.","messagePattern":"Cannot get write-only property '(.+?)'\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs","lineNumber":243,"sourceCode":"        protected override object InvokeFactoryMethod(Type type, string methodName, object[] args)\n        {\n            MethodInfo factory = GetFactoryMethod(type, methodName, args, BF_AllStaticMembers);\n            FactoryDelegate factoryDelegate;\n            if (!FactoryDelegates.TryGetValue(factory, out factoryDelegate))\n            {\n                factoryDelegate = CreateFactoryDelegate(factory);\n                FactoryDelegates.Add(factory, factoryDelegate);\n            }\n\n            return factoryDelegate.Invoke(args);\n        }\n\n        protected override object GetValue(XamlMember member, object obj)\n        {\n            MethodInfo getter = member.Invoker.UnderlyingGetter;\n            if (getter is null)\n            {\n                throw new NotSupportedException(SR.Format(SR.CantGetWriteonlyProperty, member));\n            }\n\n            PropertyGetDelegate getterDelegate;\n            if (!PropertyGetDelegates.TryGetValue(getter, out getterDelegate))\n            {\n                getterDelegate = CreateGetDelegate(getter);\n                PropertyGetDelegates.Add(getter, getterDelegate);\n            }\n\n            return getterDelegate.Invoke(obj);\n        }\n\n        protected override void SetValue(XamlMember member, object obj, object value)\n        {\n            MethodInfo setter = member.Invoker.UnderlyingSetter;\n            if (setter is null)\n            {\n                throw new NotSupportedException(SR.Format(SR.CantSetReadonlyProperty, member));","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs#L225-L261","documentation":"DynamicMethodRuntime.GetValue is called to read a member's value, but the member's invoker has no UnderlyingGetter (the property is write-only). It throws NotSupportedException with CantGetWriteonlyProperty ('Cannot get a write-only property {0}'). The library throws this because there is no getter method to invoke for the property.","triggerScenarios":"XAML load or save attempts to read (get) a member whose CLR property defines only a setter — e.g. XamlXmlWriter or XamlObjectWriter querying a write-only property, or a positional/mapped member whose getter is missing.","commonSituations":"Objects with write-only properties (e.g. password fields) included in XAML-serializable types; WPF dependency properties or wrappers exposing only setters; schema/type mapping pointing at a property without a getter.","solutions":["Add a public getter to the property, or make it read-write if serialization requires round-tripping","Exclude the write-only property from XAML by making it internal/private or marking the type appropriately for the schema","Use a different member (read-only wrapper or attached representation) to convey the value in XAML"],"exampleFix":"// before\npublic string Secret { set { _secret = value; } }\n// after\npublic string Secret { get; set; }","handlingStrategy":"try-catch","validationCode":"static void EnsureReadable(Type t, string prop) { var p = t.GetProperty(prop); if (p != null && p.GetMethod == null) throw new InvalidOperationException($\"{t}.{prop} is write-only and cannot be XAML-read\"); }","typeGuard":"static bool IsXamlReadable(System.Reflection.PropertyInfo p) => p?.GetMethod is { IsPublic: true };","tryCatchPattern":"try { Save(obj); } catch (NotSupportedException ex) when (ex.Message.Contains(\"write-only property\")) { throw new InvalidOperationException($\"Exclude write-only member: {ex.Message}\", ex); }","preventionTips":["Audit serializable types for set-only properties before enabling XAML save","Make password/secret properties internal and exclude them from schema","Prefer read-write properties on XAML-visible types"],"tags":["xaml","property","read-write","runtime"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}