jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
10.84k stars 1.15k forks source link

IPipelineBehavior<TRequest, TResponse> does not work in Android, but works in Windows #1000

Closed plavoie-nms closed 2 months ago

plavoie-nms commented 5 months ago

I have this simplified IPipelineBehavior in a MAUI project:

public class ActiveConnectionRetryPolicyBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
    where TRequest : notnull, IRequest<TResponse>
    where TResponse : Result, new()
{
    public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
    {
        if (cancellationToken.IsCancellationRequested)
        {
            var response = new TResponse();
            response.SetException(new TaskCanceledException());

            return response;
        }

        return await next().ConfigureAwait(false);
    }
}

DI:

builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(typeof(MyApp).Assembly)
                                  .AddOpenBehavior(typeof(ActiveConnectionRetryPolicyBehavior<,>)));

It works perfectly in Windows, but when running it in Android, I get this error:

System.ArgumentException
  Message=Generic implementation type 'MyApp.ActiveConnectionRetryPolicyBehavior`2' has a DefaultConstructorConstraint ('new()' constraint), but the generic service type 'MediatR.IPipelineBehavior`2' doesn't.
jbogard commented 5 months ago

I have no idea. I don't do MAUI or Android development, maybe try Stack Overflow?

davewatts commented 5 months ago

@plavoie-nms could this possibly be a trimming compilation thing?

plavoie-nms commented 5 months ago

@davewatts I have the error in debug, so no trimming:

image

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been stalled for 14 days with no activity.