PrismLibrary/Prism · error · InvalidOperationException

Handler of type is not supported

Error message

Handler of type {multicastDelegate.GetType().Name} is not supported

What it means

MulticastExceptionHandler only supports delegates whose Invoke method has 0, 1, or 2 parameters (with Exception as one of them). Any other signature throws InvalidOperationException, chained with the original exception, naming the unsupported delegate type.

Solutions

  1. Restrict the handler to 0-2 parameters, including at most Exception and the shared parameter
  2. Wrap extra context in a closure instead of extra parameters
  3. Use a custom delegate with an allowed arity

Example fix

// before
void OnError(Exception ex, string msg, int code) { }
// after
void OnError(Exception ex, string msg) { } // capture code in closure or handler state
Defensive patterns

Strategy: validation

Validate before calling

var p = handler.GetType().GetMethod("Invoke")!.GetParameters();
if (p.Length > 2) throw new ArgumentException("Handler must take at most 2 parameters", nameof(handler));

Type guard

bool isSupportedHandler(Delegate d) =>
    d.GetType().GetMethod("Invoke")!.GetParameters() is { Length: 0 or 1 or 2 };

Try / catch

try { exceptionHandler.Handle(exception, handler); }
catch (InvalidOperationException ex) { logger.LogError(ex, "Unsupported handler signature"); }

Prevention

When it happens

Trigger: Registering an exception handler delegate with 3+ parameters, e.g. (Exception, string, int) or (object sender, Exception e, string msg, object ctx).

Common situations: Wiring up event callbacks with extra context parameters and assuming the Prism exception handler accepts arbitrary signatures; often after upgrading Prism which narrowed supported handler shapes.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/411b5510be2fdacf. Report an issue: GitHub.

Appendix: source

Thrown at src/Prism.Core/Common/MulticastExceptionHandler.cs:74

    /// <exception cref="InvalidOperationException"></exception>
    public async Task HandleAsync(Exception exception, object? parameter = null)
    {
        var multicastDelegate = GetDelegate(exception.GetType());

        if (multicastDelegate is null)
            return;

        // Get Invoke() method of the delegate
        var invokeMethod = multicastDelegate.GetType().GetMethod("Invoke")
            ?? throw new InvalidOperationException($"Could not find Invoke() method for delegate of type {multicastDelegate.GetType().Name}");

        var parameters = invokeMethod.GetParameters();
        var arguments = parameters.Length switch
        {
            0 => Array.Empty<object?>(),
            1 => typeof(Exception).IsAssignableFrom(parameters[0].ParameterType) ? [exception] : [parameter],
            2 => typeof(Exception).IsAssignableFrom(parameters[0].ParameterType) ? [exception, parameter] : [parameter, exception],
            _ => throw new InvalidOperationException($"Handler of type {multicastDelegate.GetType().Name} is not supported", exception)
        };

        // Invoke the delegate
        var result = invokeMethod.Invoke(multicastDelegate, arguments);

        // If the handler is async (returns a Task), then we await the task
        if (result is Task task)
        {
            await task;
        }
#if NET6_0_OR_GREATER
        else if (result is ValueTask valueTask)
        {
            await valueTask;
        }
#endif
    }

View on GitHub (pinned to 358118cd64)