razor icon indicating copy to clipboard operation
razor copied to clipboard

Renaming the property of an inject service does not work

Open Tragetaschen opened this issue 3 years ago • 6 comments

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; }

Tragetaschen avatar Feb 24 '22 11:02 Tragetaschen

This is a compiler bug based off of the way the DesignTime code generates the @inject directive

NTaylorMullen avatar Feb 24 '22 23:02 NTaylorMullen

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.

ghost avatar Feb 28 '22 17:02 ghost

@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 avatar Feb 28 '22 17:02 mkArtakMSFT

@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

NTaylorMullen avatar Mar 01 '22 00:03 NTaylorMullen

Any progress on this? It really slows down refactoring efforts.

oldominion avatar Feb 06 '24 17:02 oldominion

The problem persists for ages and it's really anoying as it can break the code badly.

KrystofZacek avatar May 07 '24 10:05 KrystofZacek

This is still an issue in mid 2024. How can we elevate this to get it fixed? Makes refactoring much more tedious. :(

gabephudson avatar Jul 11 '24 14:07 gabephudson