{"record":{"id":"42c81fae28ba85ea","repo":"dotnet/wpf","slug":"0-1-is-a-property-without-a-getter-and-is-not-a-valid-xaml-42c81f","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/ClrEvent.cs","lineNumber":42,"sourceCode":"    class ClrEvent : ClrProperty\n    {\n        public readonly EventInfo ClrBindingEventInfo;\n        internal ClrEvent(string name, EventInfo ei, XamlType declaringType)\n            :this(name, ei, declaringType, false)\n        {\n        }\n\n        internal ClrEvent(string name, EventInfo ei, XamlType declaringType, bool isStatic)\n            : base(ei.Name, declaringType)\n        {\n            Debug.Assert(ei != null);\n            Debug.Assert(ei.Name == name);\n\n            MethodInfo mi = ei.GetAddMethod(true);\n\n            if (mi == null)\n            {\n                throw new XamlSchemaException(SR.Format(SR.SetOnlyProperty, declaringType.Name, name));\n            }\n\n            _isPublic = mi.IsPublic;\n            _isReadOnly = false;\n            _isStatic = isStatic;\n            _isAttachable = false;\n            _isEvent = true;\n\n            ClrBindingEventInfo = ei;\n        }\n\n        protected override XamlTextSyntax LookupTextSyntax()\n        {\n            return XamlTextSyntax.EventSyntax;\n        }\n\n        protected override Type LookupSystemTypeOfProperty()\n        {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrEvent.cs#L24-L60","documentation":"For a (possibly static/attachable) event, ClrEvent requires a non-null add accessor ( MethodInfo from EventInfo.GetAddMethod(true) ). If the event has no add method — meaning it cannot be subscribed to — System.Xaml throws this XamlSchemaException (reusing the SetOnlyProperty resource) because a write-only/unsubscribable member is not a valid XAML event.","triggerScenarios":"Constructing ClrEvent for an EventInfo whose GetAddMethod(true) returns null, e.g. a custom event added via AddEventHandler-only or an event whose add accessor is absent/inaccessible even with nonPublic binding.","commonSituations":"Events declared in code generated without add accessors, events on types stripped by trimming/linking that removed the add method, or reflection-based schema implementations binding to a non-event member misidentified as an event.","solutions":["Ensure the event has a public add accessor (standard C# events always do); re-declare the event normally with add/remove.","Verify the target type/assembly is not trimmed of the add method (disable linker trimming for the type).","Fix the schema code that selects the member so it only constructs ClrEvent from EventInfo with an add method."],"exampleFix":"// before: field-like event removed by linker or custom accessor missing add\npublic event EventHandler Done { remove { } }\n// after\npublic event EventHandler Done; // generates both add and remove","handlingStrategy":"type-guard","validationCode":"// before exposing an event to XAML\nvar add = eventInfo.GetAddMethod(true);\nif (add == null) skipOrLog(eventInfo.Name + \" has no add accessor\");","typeGuard":"bool IsXamlBindableEvent(EventInfo e) => e.GetAddMethod(true) != null;","tryCatchPattern":"try { ev = new ClrEvent(name, declaringType, eventInfo, isStatic); }\ncatch (XamlSchemaException ex) { log($\"Event not XAML-bindable: {ex.Message}\"); }","preventionTips":["Declare events as normal field-like events so add/remove accessors exist.","Exclude types from trimming/linker stripping that are used in XAML.","Guard schema construction with GetAddMethod checks."],"tags":["xaml","schema","events","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-21T21:30:21.729Z"}