{"record":{"id":"edfdc417252fd6dd","repo":"LuckyPennySoftware/MediatR","slug":"openbehaviortype-name-must-implement-typeof-ire-edfdc4","errorCode":null,"errorMessage":"{openBehaviorType.Name} must implement {typeof(IRequestPostProcessor<,>).FullName}","messagePattern":"(.+?) must implement (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs","lineNumber":506,"sourceCode":"    /// <summary>\r\n    /// Registers an open request post processor type against the <see cref=\"IRequestPostProcessor{TRequest,TResponse}\"/> open generic interface type\r\n    /// </summary>\r\n    /// <param name=\"openBehaviorType\">An open generic request post processor type</param>\r\n    /// <param name=\"serviceLifetime\">Optional service lifetime, defaults to <see cref=\"ServiceLifetime.Transient\"/>.</param>\r\n    /// <returns>This</returns>\r\n    public MediatRServiceConfiguration AddOpenRequestPostProcessor(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)\r\n    {\r\n        if (!openBehaviorType.IsGenericType)\r\n        {\r\n            throw new InvalidOperationException($\"{openBehaviorType.Name} must be generic\");\r\n        }\r\n\r\n        var implementedGenericInterfaces = openBehaviorType.GetInterfaces().Where(i => i.IsGenericType).Select(i => i.GetGenericTypeDefinition());\r\n        var implementedOpenBehaviorInterfaces = new HashSet<Type>(implementedGenericInterfaces.Where(i => i == typeof(IRequestPostProcessor<,>)));\r\n\r\n        if (implementedOpenBehaviorInterfaces.Count == 0)\r\n        {\r\n            throw new InvalidOperationException($\"{openBehaviorType.Name} must implement {typeof(IRequestPostProcessor<,>).FullName}\");\r\n        }\r\n\r\n        foreach (var openBehaviorInterface in implementedOpenBehaviorInterfaces)\r\n        {\r\n            RequestPostProcessorsToRegister.Add(new ServiceDescriptor(openBehaviorInterface, openBehaviorType, serviceLifetime));\r\n        }\r\n\r\n        return this;\r\n    }\r\n\r\n\r\n}","sourceCodeStart":488,"sourceCodeEnd":518,"githubUrl":"https://github.com/LuckyPennySoftware/MediatR/blob/916ef1b3d68ccdc96db8f914eaf1b32fc7db52c5/src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs#L488-L518","documentation":"Thrown by AddOpenRequestPostProcessor after the generic check passes: the type is generic but none of its generic interface definitions equals IRequestPostProcessor<,>. MediatR needs that interface to build the ServiceDescriptor.","triggerScenarios":"Registering typeof(MyGeneric<>) that is generic but implements IRequestPreProcessor<> (single arity), IPipelineBehavior<,>, or no processor interface.","commonSituations":"Open generic class wired to the wrong MediatR interface; arity mismatch; rename/refactor that drops the interface.","solutions":["Implement the open two-arity interface: class MyProcessor<TRequest,TResponse> : IRequestPostProcessor<TRequest,TResponse>.","If the type implements IRequestPreProcessor<>, register it with AddOpenRequestPreProcessor instead.","If it implements IPipelineBehavior<,>, use AddOpenBehavior."],"exampleFix":"// before\npublic class MyProcessor<TRequest> : IRequestPreProcessor<TRequest> { ... }\ncfg.AddOpenRequestPostProcessor(typeof(MyProcessor<>));\n\n// after\ncfg.AddOpenRequestPreProcessor(typeof(MyProcessor<>));","handlingStrategy":"validation","validationCode":"static bool ImplementsOpenPostProcessor(Type t) =>\n    t.IsGenericType &&\n    t.GetInterfaces()\n        .Where(i => i.IsGenericType)\n        .Select(i => i.GetGenericTypeDefinition())\n        .Any(i => i == typeof(IRequestPostProcessor<,>));\n\nif (ImplementsOpenPostProcessor(typeof(MyProcessor<,>)))\n    cfg.AddOpenRequestPostProcessor(typeof(MyProcessor<,>));","typeGuard":"static bool IsOpenRequestPostProcessor(Type t) =>\n    t.IsGenericType &&\n    t.GetInterfaces()\n        .Where(i => i.IsGenericType)\n        .Select(i => i.GetGenericTypeDefinition())\n        .Contains(typeof(IRequestPostProcessor<,>));","tryCatchPattern":null,"preventionTips":["Match the open interface's arity to the registration API.","Add a registration smoke test in your test project to catch mismatches at build time."],"tags":["di-registration","post-processor","open-generic","configuration"],"backgroundTag":null,"analyzedSha":"916ef1b3d68ccdc96db8f914eaf1b32fc7db52c5","analyzedAt":"2026-08-13T17:57:04.476Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}