{"record":{"id":"9a9fe8c68192417a","repo":"LuckyPennySoftware/MediatR","slug":"implementationtype-name-must-implement-typeof-i-9a9fe8","errorCode":null,"errorMessage":"{implementationType.Name} must implement {typeof(IStreamPipelineBehavior<,>).FullName}","messagePattern":"(.+?) must implement (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs","lineNumber":307,"sourceCode":"    /// <typeparam name=\"TImplementationType\">Closed stream behavior implementation type</typeparam>\r\n    /// <param name=\"serviceLifetime\">Optional service lifetime, defaults to <see cref=\"ServiceLifetime.Transient\"/>.</param>\r\n    /// <returns>This</returns>\r\n    public MediatRServiceConfiguration AddStreamBehavior<TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)\r\n        => AddStreamBehavior(typeof(TImplementationType), serviceLifetime);\r\n    \r\n    /// <summary>\r\n    /// Register a closed stream behavior type against all <see cref=\"IStreamPipelineBehavior{TRequest,TResponse}\"/> implementations\r\n    /// </summary>\r\n    /// <param name=\"implementationType\">Closed stream behavior implementation 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 AddStreamBehavior(Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)\r\n    {\r\n        var implementedGenericInterfaces = implementationType.FindInterfacesThatClose(typeof(IStreamPipelineBehavior<,>)).ToList();\r\n\r\n        if (implementedGenericInterfaces.Count == 0)\r\n        {\r\n            throw new InvalidOperationException($\"{implementationType.Name} must implement {typeof(IStreamPipelineBehavior<,>).FullName}\");\r\n        }\r\n\r\n        foreach (var implementedBehaviorType in implementedGenericInterfaces)\r\n        {\r\n            StreamBehaviorsToRegister.Add(new ServiceDescriptor(implementedBehaviorType, implementationType, serviceLifetime));\r\n        }\r\n\r\n        return this;\r\n    }\r\n    \r\n    /// <summary>\r\n    /// Registers an open stream behavior type against the <see cref=\"IStreamPipelineBehavior{TRequest,TResponse}\"/> open generic interface type\r\n    /// </summary>\r\n    /// <param name=\"openBehaviorType\">An open generic stream behavior 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 AddOpenStreamBehavior(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)\r\n    {\r","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/LuckyPennySoftware/MediatR/blob/916ef1b3d68ccdc96db8f914eaf1b32fc7db52c5/src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs#L289-L325","documentation":"AddStreamBehavior(Type, ServiceLifetime) mirrors AddBehavior for the streaming pipeline: it calls FindInterfacesThatClose(IStreamPipelineBehavior<,>) and throws InvalidOperationException when none are found, ensuring only valid closed stream behaviors are registered.","triggerScenarios":"Passing a Type to AddStreamBehavior that implements IPipelineBehavior<,> (request pipeline) instead of IStreamPipelineBehavior<,>, or implements neither.","commonSituations":"Confusing request vs stream pipeline behaviors; registering an open generic via AddStreamBehavior instead of AddOpenStreamBehavior; registering a non-behavior class.","solutions":["Ensure the type implements IStreamPipelineBehavior<TRequest, TResponse>.","For request (non-stream) behaviors use AddBehavior / IPipelineBehavior<,>.","For open-generic stream behaviors use AddOpenStreamBehavior(typeof(Foo<,>))."],"exampleFix":"// before\n// RequestLogging<TReq,TResp> implements IPipelineBehavior<,>\nconfiguration.AddStreamBehavior(typeof(RequestLogging<,>));\n// after\nconfiguration.AddBehavior(typeof(RequestLogging<,>));","handlingStrategy":"validation","validationCode":"var closes = implementationType.FindInterfacesThatClose(typeof(IStreamPipelineBehavior<,>)).ToList();\nif (closes.Count == 0)\n    throw new InvalidOperationException($\"{implementationType.Name} is not a closed IStreamPipelineBehavior<,>.\");","typeGuard":"static bool IsClosedStreamBehavior(Type t) =>\n    t.FindInterfacesThatClose(typeof(IStreamPipelineBehavior<,>)).Any();","tryCatchPattern":null,"preventionTips":["Confirm the type implements IStreamPipelineBehavior<TRequest, TResponse>.","Use AddBehavior / IPipelineBehavior<,> for non-stream pipelines and AddOpenStreamBehavior for open generics."],"tags":["stream-pipeline-behavior","registration","di","type-validation"],"backgroundTag":null,"analyzedSha":"916ef1b3d68ccdc96db8f914eaf1b32fc7db52c5","analyzedAt":"2026-08-13T17:57:04.476Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}