AvaloniaUI/Avalonia · error · InvalidOperationException

The MethodAccessorPlugin does not support dynamic matching

Error message

The MethodAccessorPlugin does not support dynamic matching

What it means

MethodAccessorPlugin exposes a known MethodInfo as a delegate for compiled bindings. The IPropertyAccessorPlugin.Match method (used by the reflection-binding accessor pipeline to pick a plugin by object+name) throws InvalidOperationException because this plugin cannot match dynamically — it only works with a pre-supplied MethodInfo. Hitting it means the plugin was incorrectly placed in the reflection accessor chain.

Source

Thrown at src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs:20

using System.Diagnostics;
using System.Reflection;

namespace Avalonia.Data.Core.Plugins;

internal class MethodAccessorPlugin : IPropertyAccessorPlugin
{
    private readonly MethodInfo _method;
    private readonly Type _delegateType;

    public MethodAccessorPlugin(MethodInfo method, Type delegateType)
    {
        _method = method;
        _delegateType = delegateType;
    }

    public bool Match(object obj, string propertyName)
    {
        throw new InvalidOperationException("The MethodAccessorPlugin does not support dynamic matching");
    }

    public IPropertyAccessor Start(WeakReference<object?> reference, string propertyName)
    {
        Debug.Assert(_method.Name == propertyName);
        return new Accessor(reference, _method, _delegateType);
    }

    private sealed class Accessor : PropertyAccessorBase
    {
        public Accessor(WeakReference<object?> reference, MethodInfo method, Type delegateType)
        {
            _ = reference ?? throw new ArgumentNullException(nameof(reference));
            _ = method ?? throw new ArgumentNullException(nameof(method));

            PropertyType = delegateType;

            if (method.IsStatic)

View on GitHub (pinned to 11c5427268)

Solutions

  1. Do not add MethodAccessorPlugin to the reflection accessor chain; it is for compiled bindings only.
  2. Use InpcPropertyAccessorPlugin for reflection bindings against CLR objects.
  3. Keep the compiled-binding plugin set separate from the reflection-binding plugin set.
Defensive patterns

Strategy: validation

Validate before calling

// Never place compiled-binding-only plugins in the reflection accessor chain.
// When building the plugin list, filter them out:
plugins = plugins.Where(p => p is not MethodAccessorPlugin).ToList();

Prevention

When it happens

Trigger: Registering MethodAccessorPlugin in the property accessor plugin list (e.g. Data.Core.Accessor.PluginHandlers / a custom chain) and then resolving a reflection (string) binding that probes Match on each plugin.

Common situations: Misconfiguring the accessor plugin pipeline; third-party code mixing compiled-binding plugins into the reflection binding path; manual instantiation and use of MethodAccessorPlugin.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/30b674b1e67885bd. Report an issue: GitHub.