public async Task<Stream> HandleFileRequest(FileRequest request) { Console.WriteLine("Call to HandleRequest"); var requestType = request.GetType(); var isValidRequest = requestType.GetInterfaces().Any(x => x.IsGenericType && (typeof(IAsyncRequest<>).IsAssignableFrom(x.GetGenericTypeDefinition()) || typeof(IRequest<>).IsAssignableFrom(x.GetGenericTypeDefinition())) ); if (!isValidRequest) { throw new ArgumentException("Unprocessable request"); } //var isAsyncRequest = requestType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IAsyncRequest<>)); var responseStream = new MemoryStream(); request.SetStream(responseStream); //if (isAsyncRequest) //{ // await _mediator.SendAsync(request); //} _mediator.Send(request); responseStream.Position = 0; return responseStream; }