Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.TypeLoadException - GenericArguments[x] on '...' violates the constraint of type parameter response. #823

Closed
aldrashan opened this issue Jan 24, 2023 · 1 comment

Comments

@aldrashan
Copy link

I've defined a couple pipelines and some of them have constraints.
Example:

internal class ValidationPipeline<Request, Response> : IPipelineBehavior<Request, Response>
where Request : IRequest<Response>
where Response : class, ICommandResult

While these pipelines do get executed for the correct arguments (constraints), a System.TypeLoadException error is thrown for Request/Response combinations that violate these constraints. This doesn't break the code, but it does worry me that they show up in the diagnostic tools/logs.

I guess it has something to do with how we register these pipelines?

services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationPipeline<,>));

See also the following issue

Should we modify these pipelines to check our types within the handlers? Would this benefit us at all or is it unnecessary?

@jbogard
Copy link
Owner

jbogard commented Jan 24, 2023

Not necessary, but feel free to upvote this issue: dotnet/runtime#28033 as the only way today to reliably check generic constraints is to try to close the open type and catch the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants