Renaming the property of an inject service does not work
Describe the bug:
I have an @injected service and try to rename the property holding the value.
Version used: VS2022 17.2 Preview 1
To reproduce:
@inject IEnumerable<int> emumerable // rename here
@code
{
void M()
{
foreach (var a in emumerable) // expect result here
{
}
}
}
Try to rename emumerable to enumerable.
Expected behavior:
All occurences of the emumerable name within the Razor file should be replaced with enumerable
Actual behavior: The example usage of the instance in the foreach loop is not renamed and left behind as a compilation error.
Additional context:
There's already a highlighting issue before the rename operation. Clicking either the @inject property or the usage in the foreach does not highlight the other. Both also show a different tooltip, what C# language thing they are: The @inject property is (local variable) object emumerable while the usage in the foreach loop is IEnumerable<int> Test.emumerable { get; set; }
This is a compiler bug based off of the way the DesignTime code generates the @inject directive
Thanks for contacting us.
We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
@NTaylorMullen can you please share more details about what specifically causes this and maybe you even know what needs to change to fix this? Thanks!
@mkArtakMSFT absolutely. In this case the user has @inject IEnumerable<int> enumerable. At codegen time this generates two separate lambdas to power the IntelliSense:
__o = () => {
var
#line 1
enumerable
#line default
new object();
};
and
__o = () => {
varenumerable
#line default
__typehelper = default;
};
Note how neither one of these "helpers" actually reference the actual property which means if a user attempts to rename the parameter they wont actually have the intended effect
Any progress on this? It really slows down refactoring efforts.
The problem persists for ages and it's really anoying as it can break the code badly.
This is still an issue in mid 2024. How can we elevate this to get it fixed? Makes refactoring much more tedious. :(