-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Remove RequiresUnreferencedCode from low-level endpoint map methods #42519
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
Conversation
This makes sense to me. |
This is the bug the change originally fixed: #39956 app.Map("/Fails1", Fails1);
app.Run();
static async Task<string> Fails1(HttpContext context)
{
var response = await Task.FromResult("response");
return response;
} So The only non-runtime fix I can imagine is adding an explicit overload for it, i.e. Alternatively, we leave the runtime reflection as it is, but suppress it. The downside is someone who happens to use |
What happens if someone unknowingly because of the suppression thinks it's safe to trim their app when in fact they're relying on RDFs return value serialization? Could fields on the returned values be stripped? That seems worse than just ignoring the return value altogether which is why I said this change to just to remove this functionality from the RequestDelegate overload made sense to me. It's certainly unfortunate that trimming stops us from just making return value serialization work for people who do not trim and accidentally use the RequestDelegate overload, but I still think that's not as bad as suppressing a warning that really shouldn't be suppressed. It's easy enough to manually cast to Delegate if you need to. |
1 similar comment
What happens if someone unknowingly because of the suppression thinks it's safe to trim their app when in fact they're relying on RDFs return value serialization? Could fields on the returned values be stripped? That seems worse than just ignoring the return value altogether which is why I said this change to just to remove this functionality from the RequestDelegate overload made sense to me. It's certainly unfortunate that trimming stops us from just making return value serialization work for people who do not trim and accidentally use the RequestDelegate overload, but I still think that's not as bad as suppressing a warning that really shouldn't be suppressed. It's easy enough to manually cast to Delegate if you need to. |
Here is an idea: write an analyzer that detects using a method that returns Issue: #42523 |
This is a good change |
RequiresUnreferencedCode
from low-level endpoint map methods. These methods should be reflection-free. No longer support checking the request delegate method at runtime, inspecting its return type, and generating a wrapper.@halter73 You made this change in #42195. Are you ok with reverting it? Does it still make sense to keep the test that I had to modify after reverting the change?