roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

"Extract Method" changes the behavior of a VB.NET program

Open vsfeedback opened this issue 1 month ago • 1 comments

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


[severity:It’s more difficult to complete my work]
Repro steps:

  1. Create the following VB program:
Public Module Module1
    Public Sub Main()
        Console.WriteLine("A")
        If Math.Abs(1) = 1 Then Return
        Console.WriteLine("B")
    End Sub
End Module
  

Note that this program outputs “A”.

  1. Select the first two lines inside Sub Main and use the “Extract Method” refactoring tooltip. This creates the following program:
Public Module Module1
    Public Sub Main()
        NewMethod()
        Console.WriteLine("B")
    End Sub
    
Private Sub NewMethod()
        Console.WriteLine("A")
        If Math.Abs(1) = 1 Then Return
    End Sub
End Module
  

Expected result: The new program behaves exactly like the old program.
Actual result: The new program outputs both “A” and “B”.

This is a bug, since the “extract method” refactoring should not change the behavior of the program. It seems to be a VB. NET-only issue, since the same refactoring works fine in the equivalent C# code (creating a method that returns a “flowControl” bool).


Original Comments

Feedback Bot on 11/11/2025, 01:39 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.

Muhammad Nabil Fikri Adenan (Centific Technologies Inc) [MSFT] on 11/12/2025, 01:10 PM:

Thanks for your sharing the detail steps, I can reproduce this issue through your shared steps and this issue has been escalated for further investigation, if there is any process, I will inform you immediately.

vsfeedback avatar Dec 05 '25 14:12 vsfeedback

This repro on VS 2022 Professional 17.14.20

Image

deepakrathore33 avatar Dec 05 '25 14:12 deepakrathore33