dotnet/wpf · error · XamlSchemaException

' '.' ' is a property without a getter and is not a valid…

Error message

'{0}'.'{1}' is a property without a getter and is not a valid XAML property.

What it means

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.

Solutions

  1. Ensure the event has a public add accessor (standard C# events always do); re-declare the event normally with add/remove.
  2. Verify the target type/assembly is not trimmed of the add method (disable linker trimming for the type).
  3. Fix the schema code that selects the member so it only constructs ClrEvent from EventInfo with an add method.

Example fix

// before: field-like event removed by linker or custom accessor missing add
public event EventHandler Done { remove { } }
// after
public event EventHandler Done; // generates both add and remove
Defensive patterns

Strategy: type-guard

Validate before calling

// before exposing an event to XAML
var add = eventInfo.GetAddMethod(true);
if (add == null) skipOrLog(eventInfo.Name + " has no add accessor");

Type guard

bool IsXamlBindableEvent(EventInfo e) => e.GetAddMethod(true) != null;

Try / catch

try { ev = new ClrEvent(name, declaringType, eventInfo, isStatic); }
catch (XamlSchemaException ex) { log($"Event not XAML-bindable: {ex.Message}"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/42c81fae28ba85ea. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrEvent.cs:42

    class ClrEvent : ClrProperty
    {
        public readonly EventInfo ClrBindingEventInfo;
        internal ClrEvent(string name, EventInfo ei, XamlType declaringType)
            :this(name, ei, declaringType, false)
        {
        }

        internal ClrEvent(string name, EventInfo ei, XamlType declaringType, bool isStatic)
            : base(ei.Name, declaringType)
        {
            Debug.Assert(ei != null);
            Debug.Assert(ei.Name == name);

            MethodInfo mi = ei.GetAddMethod(true);

            if (mi == null)
            {
                throw new XamlSchemaException(SR.Format(SR.SetOnlyProperty, declaringType.Name, name));
            }

            _isPublic = mi.IsPublic;
            _isReadOnly = false;
            _isStatic = isStatic;
            _isAttachable = false;
            _isEvent = true;

            ClrBindingEventInfo = ei;
        }

        protected override XamlTextSyntax LookupTextSyntax()
        {
            return XamlTextSyntax.EventSyntax;
        }

        protected override Type LookupSystemTypeOfProperty()
        {

View on GitHub (pinned to 81131a70a4)