Search code examples
c#asp.net-coremediatr

When executing API method using MediatR, getting an error


It is my 1st time implementing Mediator but now I get the following error when calling API method:

ERROR

{"error":"Enumerator failed to MoveNextAsync."}

DI

services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationBehavior<,>));

Base API

[ApiController]
[Route("api/[controller]")]
public abstract class ApiController : ControllerBase
{
    private IMediator _mediator;

    protected IMediator Mediator => _mediator ??= HttpContext.RequestServices.GetService<IMediator>();
}

API

[HttpGet]
[Route("client/{clientId}/template/list")]
public async Task<ActionResult<TemplateListDTO>> GetClientTemplateList(long clientId)
{
    return await Mediator.Send(new GetClientTemplateListQuery { ClientId = clientId });
}

I am using DotNet core 3.1


Solution

  • I found the problem, it wasn't with Mediator. An exception occurred in the pipeline which was handled incorrectly and couldn't go to the next() pipeline.