-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Suppress generic constraint exceptions in GetPublicNoArgExtensionMethods #3999
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
Suppress generic constraint exceptions in GetPublicNoArgExtensionMethods #3999
Conversation
GetPublicNoArgExtensionMethods tries to instantiate arbitrary generic methods with arbitrary type arguments, which can fail if those arguments don't meet any constraints defined on the generic parameters. Automapper isn't doing the required checking for constraint validation today, resulting in exceptions escaping; multiple existing Automapper unit tests fail on .NET 7 as a result. This works around it by eating the ArgumentException that comes from MakeGenericMethod (there's no exposed compatibility-checking function, and so while not usually recommended, the most reliable thing here is to simply catch the errors stemming from the validation MakeGenericMethod performs).
|
Related feature request to not have to do this exception silliness: le sigh |
|
Maybe we should simply skip all methods with generic constraints. |
|
I think that might be more confusing... |
|
I guess it's easy to skip them in user code. |
|
@jbogard @lbargaoanu we (.NET team) would like to collaborate with you on this issue. We recognize that AutoMapper library is used by many applications, and it is important for us that these applications continue to work with .NET 7. Can you please contact us on [email protected]? Thanks! |
|
I'm on vacation for the next two weeks :) |
|
Thanks @lbargaoanu. We wanted to get some information as follows:
.NET 7 GA is this November, so we have a couple of weeks to evaluate the options. Have a great vacation! We look forward to hearing back from you. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
GetPublicNoArgExtensionMethods tries to instantiate arbitrary generic methods with arbitrary type arguments, which can fail if those arguments don't meet any constraints defined on the generic parameters. Automapper isn't doing the required checking for constraint validation today, resulting in exceptions escaping; multiple existing Automapper unit tests fail on .NET 7 as a result. This works around it by eating the ArgumentException that comes from MakeGenericMethod (there's no exposed compatibility-checking function, and so while not usually recommended, the most reliable thing here is to simply catch the errors stemming from the validation MakeGenericMethod performs).
Fixes #3988