{"record":{"id":"e8fd7e62a5afd99f","repo":"dotnet/wpf","slug":"0-1-is-a-property-without-a-getter-and-is-not-a-valid-xaml-e8fd7e","errorCode":null,"errorMessage":"'{0}'.'{1}' is a property without a getter and is not a valid XAML property.","messagePattern":"'(.+?)'\\.'(.+?)' is a property without a getter and is not a valid XAML property\\.","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs","lineNumber":80,"sourceCode":"        public ClrProperty(string name, PropertyInfo pi, XamlType declaringType)\n            : this(name, pi, declaringType, false)\n        {\n        }\n\n        private ClrProperty(string name, PropertyInfo pi, XamlType declaringType, bool isStatic)\n        {\n            Debug.Assert(pi != null);\n            Debug.Assert(pi.Name == name);\n#if DEBUG\n            if (declaringType == null)\n            {\n                throw new XamlInternalException(\"Asserting that the declaringType should never be null\");\n            }\n#endif\n            MethodInfo mi = pi.GetGetMethod(true);\n            if (mi == null)\n            {\n                throw new XamlSchemaException(SR.Format(SR.SetOnlyProperty, declaringType.Name, name));\n            }\n\n            _declaringType = declaringType;\n            _name = pi.Name;\n            _isPublic = mi.IsPublic;\n            _isReadOnly = !pi.CanWrite;\n            _isStatic = isStatic;\n            ClrBindingPropertyInfo = pi;\n\n            _isAttachable = false;\n            _isEvent = false;\n\n            OtherInitialization();\n        }\n\n\n\n        private void OtherInitialization()","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs#L62-L98","documentation":"ClrProperty wraps a CLR PropertyInfo for XAML schema use. It demands a getter: if pi.GetGetMethod(true) returns null the property is write-only, which is not a valid XAML property, so a XamlSchemaException (SR.SetOnlyProperty) is thrown naming declaringType and the property.","triggerScenarios":"Constructing ClrProperty from a PropertyInfo that has no get accessor at all (public or private), e.g. a property with only a set accessor.","commonSituations":"Write-only properties in view-models or custom markup-extension targets referenced from XAML; code-generation emitting set-only properties; languages/platforms where GetGetMethod(true) still returns null because no getter was declared.","solutions":["Add a getter to the property (it can be less accessible, e.g. private, but must exist).","Replace the set-only property with a public field or a full property.","Point the XAML schema at a different member that is readable."],"exampleFix":"// before\npublic string Secret { set { _secret = value; } }\n// after\npublic string Secret { get; set; }\n// or keep setter private getter:\npublic string Secret { private get; set; }","handlingStrategy":"type-guard","validationCode":"// before using a property in XAML\nif (propInfo.GetGetMethod(true) == null)\n    throw new InvalidOperationException($\"{propInfo.DeclaringType}.{propInfo.Name} is write-only; add a getter\");","typeGuard":"bool IsReadable(PropertyInfo p) => p.GetGetMethod(true) != null;\nbool IsXamlUsable(PropertyInfo p) => p.CanRead || p.CanWrite && p.GetGetMethod(true) != null;","tryCatchPattern":"try { member = new ClrProperty(name, propInfo, declaringType, schemaContext); }\ncatch (XamlSchemaException ex) { log($\"Write-only property: {ex.Message}\"); }","preventionTips":["Never declare set-only properties on XAML-exposed types.","If the getter must be hidden, make it private/internal rather than omitting it.","Scan assemblies for CanRead == false properties before XAML use."],"tags":["xaml","schema","properties","reflection"],"backgroundTag":"missing-dependency","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"}