{"record":{"id":"7736833ff0c19948","repo":"LuckyPennySoftware/MediatR","slug":"requesttype-name-does-not-implement-istreamreque","errorCode":null,"errorMessage":"{requestType.Name} does not implement IStreamRequest<TResponse>","messagePattern":"(.+?) does not implement IStreamRequest<TResponse>","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/MediatR/Mediator.cs","lineNumber":195,"sourceCode":"        var items = streamHandler.Handle(request, _serviceProvider, cancellationToken);\r\n\r\n        return items;\r\n    }\r\n\r\n\r\n    public IAsyncEnumerable<object?> CreateStream(object request, CancellationToken cancellationToken = default)\r\n    {\r\n        if (request == null)\r\n        {\r\n            throw new ArgumentNullException(nameof(request));\r\n        }\r\n\r\n        var handler = _streamRequestHandlers.GetOrAdd(request.GetType(), static requestType =>\r\n        {\r\n            var requestInterfaceType = requestType.GetInterfaces().FirstOrDefault(static i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStreamRequest<>));\r\n            if (requestInterfaceType is null)\r\n            {\r\n                throw new ArgumentException($\"{requestType.Name} does not implement IStreamRequest<TResponse>\", nameof(request));\r\n            }\r\n\r\n            var responseType = requestInterfaceType.GetGenericArguments()[0];\r\n            var wrapperType = typeof(StreamRequestHandlerWrapperImpl<,>).MakeGenericType(requestType, responseType);\r\n            var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($\"Could not create wrapper for type {requestType}\");\r\n            return (StreamRequestHandlerBase)wrapper;\r\n        });\r\n\r\n        var items = handler.Handle(request, _serviceProvider, cancellationToken);\r\n\r\n        return items;\r\n    }\r\n}\r\n","sourceCodeStart":177,"sourceCodeEnd":209,"githubUrl":"https://github.com/LuckyPennySoftware/MediatR/blob/916ef1b3d68ccdc96db8f914eaf1b32fc7db52c5/src/MediatR/Mediator.cs#L177-L209","documentation":"The non-generic CreateStream(object) overload reflects over the object's interfaces looking for IStreamRequest<>. If none is found, the object is not a stream request, so ArgumentException is thrown naming the type and the missing IStreamRequest<TResponse> contract.","triggerScenarios":"Calling mediator.CreateStream(someObject) where someObject implements IRequest<> (a normal request) or nothing — anything other than IStreamRequest<TResponse>.","commonSituations":"Dispatching through a non-generic boundary (messaging, reflection) and passing a normal IRequest instead of IStreamRequest; forgetting to mark a query as a stream request; confusing Send and CreateStream.","solutions":["Mark the type `public record StreamX : IStreamRequest<Y>` and call CreateStream.","If the payload is a normal request, call Send, not CreateStream.","Prefer the generic CreateStream<TResponse>(IStreamRequest<TResponse>) overload to get compile-time checking."],"exampleFix":"// before\npublic record Poll(int Id) : IRequest<int>;\nmediator.CreateStream((object)new Poll(1)); // ArgumentException\n// after\npublic record Poll(int Id) : IStreamRequest<int>;\nmediator.CreateStream(new Poll(1));","handlingStrategy":"type-guard","validationCode":"var isStream = request.GetType().GetInterfaces()\n    .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStreamRequest<>));\nif (!isStream) throw new ArgumentException($\"{request.GetType().Name} is not an IStreamRequest<T>.\", nameof(request));","typeGuard":"static bool IsStreamRequest(object o) =>\n    o.GetType().GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStreamRequest<>));","tryCatchPattern":null,"preventionTips":["Prefer the generic CreateStream<TResponse>(IStreamRequest<TResponse>) overload.","Mark stream-query types with IStreamRequest<T>.","Do not pass normal IRequest objects to CreateStream."],"tags":["mediator","stream","istreamrequest","type-validation","reflection"],"backgroundTag":null,"analyzedSha":"916ef1b3d68ccdc96db8f914eaf1b32fc7db52c5","analyzedAt":"2026-08-13T17:57:04.476Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}