Skip to content

Extract method of part of static local method creates non static method causing compile error #58013

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


Create new C# project (I targeted .NET 6)
This creates a new style project with no "class" or "namespace"
Delete content and paste in this:

static void X(string s)
{
s = s.Trim();
}

Select the "s = s.Trim();" line and Ctrl-. to refactor and choose Extract Method

You get a build error

Severity Code Description Project File Line Suppression State
Error CS8421 A static local function cannot contain a reference to 'NewMethod'. ConsoleApp32 C:\Users\danmose\source\repos\ConsoleApp32\ConsoleApp32\Program.cs 4 Active
Message IDE0062 Local function can be made static ConsoleApp32 C:\Users\danmose\source\repos\ConsoleApp32\ConsoleApp32\Program.cs 7 Active

It should make the new method static.


Original Comments

Feedback Bot on 11/28/2021, 10:07 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Metadata

Metadata

Assignees

Labels

Area-IDEBugDeveloper CommunityThe issue was originally reported on https://developercommunity.visualstudio.comhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions