Open WeihanLi opened 10 months ago
Thanks for the bug report, @WeihanLi! Yes, we should avoid emitting this diagnostic for web apps not configured with the routing middleware.
Let me see how easy this is to fix on the analyzer side...
I just took a quick look, but it seems like this would be relatively straight forward. Right now we're emitting the diagnostic for any method on WebApplication
.
Maybe we could pass an array of excluded method symbols to the IsDisallowedMethod
method in WebApplicationBuilderAnalyzer
? That way we could check that the method we're analyzing isn't one we want to exclude, after we check the method's containing type here.
Edit: I took a closer look into this, and it's definitely not as straightforward as I originally thought, as discussed below.
Seemed we're emitting the ASP0014
diagnostic for UseEndpoints
method only, we may need to distinguish whether the WebApplication
is an empty web application, if it is, we may need to exclude it, while it seems there's no property or something indicates if it's empty for now
Seemed we're emitting the ASP0014 diagnostic for UseEndpoints method only, we may need to distinguish whether the WebApplication is an empty web application, if it is, we may need to exclude it, while it seems there's no property or something indicates if it's empty for now
Yep! The challenge here is that we want to continue emitting the warning about UseEndpoints
for non-empty WebApplicationBuilder
s. There's not a straightforward way for us to determine if a given builder is empty or not unless we do some flow analysis to determine if it was constructed via CreateEmptyBuilder.
Backlogging this for now. Was hopping I'd be able to tackle this for 9.0-preview1 but that turned out to not be the case.
PRs welcome on this though!
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Since the empty WebAplicationBuilder would not register routing, maybe we could disable the
ASP0014
using top-level route registrations diagnostic?We may use the code like below, currently we would get![image](https://github.com/dotnet/aspnetcore/assets/7604648/43c77567-5609-4531-aa98-95d9ee910e53)
ASP0014
warningDescribe the solution you'd like
Ignore it when using the empty
WebApplicationBuilder
since no default global routingAdditional context
No response