-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Make-method-async code fix breaks ASP.NET MVC action routing after 'Async' suffix is appended to method name #4849
Comments
From @jeremymeng on August 28, 2017 18:36 ASP.NET uses the controller action names to locate the views. If there's an |
It should be added that Roslyn allows project systems to fix up identifiers after a rename occurs (by providng an event). However, that doesn't help in this case as routing is rule based. One could argue that the routing engine could handle that, but this could have potential for breaking changes. So as written, I think this should be moved to https://github.com/aspnet/Mvc/issues. However, one could also argue that the "make this method async"-fixer shouldn't also rename the method, but that seems like the wrong direction to me. /cc @CyrusNajmabadi |
From @CyrusNajmabadi on August 28, 2017 18:57
I agree. While things break in this case, we do the right thing for the majority of cases. 'Async' suffix is a strong pattern in the framework, and should be something we push code toward. If we don't do this, it just means that users have to take the extra step of having to rename the method. If you have to do a lot of this, it's an onerous process. Here it looks like we have an API that uses stringly typed connections. If that framework wants to work that way, it should hook into the existing roslyn notifications for when this happens so it can appropriately update things. Also, it should consider providing an analyzer to tell the user when the names don't match the routing so that things can be clearer. Finally, it seems to me like MVC should just support the Async extension. It's a core .NET naming style. |
From @jeremymeng on August 28, 2017 19:5 Agree on the value of "Async" suffix. It would be great if ASP.NET MVC can handle this. Can you please help move the issue over to them? |
This is currently by-design; MVC with conventional routes does matching based on method names, regardless of any perceived "suffix." @rynowak - I think we used to have some rules that relaxed some of these requirements in MVC 1-5, but I guess we got rid of them. Is it because everything is now async, so there was no point trying to distinguish async methods from non-async methods, so we supported just exact name matches? It would be a breaking change to start supporting this conditional match, but we could consider it in 3.0. |
We'll look at making this change in 3.0.0, which is the next time we can do this kind of breaking change. |
My team enforces 'Async' suffix in the async methods so we do have to suppress the warnings in all the async action methods. @Eilon is this still on radar of ASP.NET Core 3.0? @rynowak before 3.0, would it possible to provide a workaround by implementing Thanks, |
If you need an unblocker, the easiest way to do this would be to write a convention.
You can register this like:
|
@Eilon \ @mkArtakMSFT would this entail an announcement or would we just make note of it in the 3.0 migration notes? |
Seems pretty minor, so I'd say not worth it. |
From @jeremymeng on August 28, 2017 18:31
Version Used:
Steps to Reproduce:
Index()
toTask<IActionResult>
await Task.Delay(1);
insideIndex()
Now the method looks like
Actual Behavior:
HTTP 404
if rename the method back to
Index()
F5 works again.Copied from original issue: dotnet/roslyn#21770
The text was updated successfully, but these errors were encountered: