-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Reflection Invoke does not check ContainsGenericParameters #95245
Comments
We can probably follow dotnet/runtimelab#858 and add that check there too. |
I don't think this should be fixed in this way. |
If a non-generic method gets completely trimmed away, we don't throw an exception; the reflection stack acts as if it was never there. Try: using System;
class Program
{
static Type programType = typeof(Program);
static string unusedMethodString = "UnusedMethod";
public static void UnusedMethod() => Console.WriteLine("Hello");
static void Main()
{
programType.GetMethod(unusedMethodString).Invoke(null, Array.Empty<object>());
}
} This will throw a You will also get a compile-time warning that there's a problem:
(You need to opt into the warning with (If you change the above program to not use static fields, the compiler can actually figure this reflection out and there will be no warnings.) The fix I proposed won't change this experience. |
Still reproduces on .NET 9.0 daily builds, should probably be moved to dotnet/runtime now |
Expected Behavior:
Throws
Actual Behavior:
Throws
The text was updated successfully, but these errors were encountered: