{"record":{"id":"411b5510be2fdacf","repo":"PrismLibrary/Prism","slug":"handler-of-type-multicastdelegate-gettype-name-is-not","errorCode":null,"errorMessage":"Handler of type {multicastDelegate.GetType().Name} is not supported","messagePattern":"Handler of type (.+?) is not supported","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Common/MulticastExceptionHandler.cs","lineNumber":74,"sourceCode":"    /// <exception cref=\"InvalidOperationException\"></exception>\n    public async Task HandleAsync(Exception exception, object? parameter = null)\n    {\n        var multicastDelegate = GetDelegate(exception.GetType());\n\n        if (multicastDelegate is null)\n            return;\n\n        // Get Invoke() method of the delegate\n        var invokeMethod = multicastDelegate.GetType().GetMethod(\"Invoke\")\n            ?? throw new InvalidOperationException($\"Could not find Invoke() method for delegate of type {multicastDelegate.GetType().Name}\");\n\n        var parameters = invokeMethod.GetParameters();\n        var arguments = parameters.Length switch\n        {\n            0 => Array.Empty<object?>(),\n            1 => typeof(Exception).IsAssignableFrom(parameters[0].ParameterType) ? [exception] : [parameter],\n            2 => typeof(Exception).IsAssignableFrom(parameters[0].ParameterType) ? [exception, parameter] : [parameter, exception],\n            _ => throw new InvalidOperationException($\"Handler of type {multicastDelegate.GetType().Name} is not supported\", exception)\n        };\n\n        // Invoke the delegate\n        var result = invokeMethod.Invoke(multicastDelegate, arguments);\n\n        // If the handler is async (returns a Task), then we await the task\n        if (result is Task task)\n        {\n            await task;\n        }\n#if NET6_0_OR_GREATER\n        else if (result is ValueTask valueTask)\n        {\n            await valueTask;\n        }\n#endif\n    }\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Common/MulticastExceptionHandler.cs#L56-L92","documentation":"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.","triggerScenarios":"Registering an exception handler delegate with 3+ parameters, e.g. (Exception, string, int) or (object sender, Exception e, string msg, object ctx).","commonSituations":"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.","solutions":["Restrict the handler to 0-2 parameters, including at most Exception and the shared parameter","Wrap extra context in a closure instead of extra parameters","Use a custom delegate with an allowed arity"],"exampleFix":"// before\nvoid OnError(Exception ex, string msg, int code) { }\n// after\nvoid OnError(Exception ex, string msg) { } // capture code in closure or handler state","handlingStrategy":"validation","validationCode":"var p = handler.GetType().GetMethod(\"Invoke\")!.GetParameters();\nif (p.Length > 2) throw new ArgumentException(\"Handler must take at most 2 parameters\", nameof(handler));","typeGuard":"bool isSupportedHandler(Delegate d) =>\n    d.GetType().GetMethod(\"Invoke\")!.GetParameters() is { Length: 0 or 1 or 2 };","tryCatchPattern":"try { exceptionHandler.Handle(exception, handler); }\ncatch (InvalidOperationException ex) { logger.LogError(ex, \"Unsupported handler signature\"); }","preventionTips":["Keep handler signatures to (Exception), (Exception, T), or (T, Exception)","Move extra context into closures or class state","Check Prism docs for supported handler shapes before registering"],"tags":["delegate","unsupported-signature","prism"],"backgroundTag":"unsupported-operation","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}