Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Yellow cursor(current line) does not move flexibly in Debug mode when using Visual Basic in Visual Studio 2022. By the nature of the debug process, it is necessary to be able to move the cursor to the line we want. When I try to position the cursor at a certain line of code, I receive an error. However, if I add a simple blank line to the end of the line, the error goes away. We can work on 2019 without any problems.
Does anyone have any ideas

Detailed Error Report

What I have tried:

Updated Visual Studio last version.
To avoid language problems, a clean installation was made on Windows in English.
Posted
Comments
ftpx 16-Nov-23 5:35am    
I think I didn't fully explain my problem. I did a clean install on a virtual machine and took a screen recording. Please watch the video in the link.

SS Video

1 solution

The "Yellow cursor" isn't a cursor at all. It's just highlight the next line of code that's going to be executed when your code is stopped in the debugger.

You do not get to "flexibly" move that highlight anywhere you want. There are limitations on what is possible. For example, when your code stops at a breakpoint in a method, you cannot right-click a line in another method and "Set Next Statement" to continue running code from that new point without causing a huge problem with the stack and screwing up variable scopes.

The yellow highlight works as expected and has for a really long time.

I can't replicate the problem in my copy of VS2022 v17.7.6, so I'm wondering if you have an extension loaded that's causing the problem, and it may be why MS can't replicate the problem either.
 
Share this answer
 
v2
Comments
Andre Oosthuizen 15-Nov-23 13:12pm    
My +5, extension is most probably the cause, we had a similar case before. OP mentions a clean install, was any extensions added or was it tested as is immediately after the clean install?
ftpx 16-Nov-23 1:00am    
Yes, tested with a clean installed windows and visual studio with no plugins. Even tested on different computers. By the way, the code doesn't matter. I have created many sample projects. If you open the same code with VS2019 there is no problem. I can set the line I want the code to continue by dragging and dropping with the mouse. I have been doing this for years :)

I am attaching a sample code. Put a breakpoint on the first line of the PingProccess method and try changing the line in the same method. It will block you with a red forbidden sign. Add a few empty lines after the line. Now you can go to that line. But there seems to be no fixed logic.

Note: If I write the same code exactly in C#, there is no problem.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim p As New Pinger
        p.Start("192.168.1.1254")
    End Sub
End Class

Class Pinger
    Private who_ As String

    Private pingSender_ As Ping
    Public Event ReturnValue(value As String)

    Private cancel_ As Boolean = False

    Sub New()
        pingSender_ = New Ping
        AddHandler pingSender_.PingCompleted, AddressOf pingSender__PingCompleted
    End Sub

    Public Sub Cancel()
        cancel_ = True
        pingSender_.SendAsyncCancel()
    End Sub

    Public Sub Start(who As String)
        who_ = who
        RaiseEvent ReturnValue("Starting")
        PingProccess()
    End Sub

    Private Sub PingProccess()
        If cancel_ Then Exit Sub
        Dim waiter_ As New AutoResetEvent(False)

        Thread.Sleep(1000)
        Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        Dim buffer() As Byte = Encoding.ASCII.GetBytes(data)
        Dim timeout As Integer = 1000
        Dim options As New PingOptions(64, True)
        pingSender_.SendAsync(who_, timeout, buffer, options, waiter_)
        If cancel_ Then Exit Sub
        Application.DoEvents()

    End Sub

    Private Sub pingSender__PingCompleted(sender As Object, e As PingCompletedEventArgs)

        If e.Cancelled Then
            RaiseEvent ReturnValue("Ping cancel")
            CType(e.UserState, AutoResetEvent).Set()
        End If

        If Not IsNothing(e.Error) Then
            RaiseEvent ReturnValue("Ping error : ")
            RaiseEvent ReturnValue(e.Error.ToString)
            CType(e.UserState, AutoResetEvent).Set()
        End If

        Dim reply As PingReply = e.Reply
        DisplayReply(reply)

        CType(e.UserState, AutoResetEvent).Set()

        PingProccess()

    End Sub



    Private Sub DisplayReply(reply As PingReply)
        If IsNothing(reply) Then

        ElseIf reply.Status = IPStatus.Success Then
            RaiseEvent ReturnValue("Reply from " & reply.Address.ToString & ": bytes= " & reply.Buffer.Length & " time =  " & reply.RoundtripTime & "ms TTL=" & reply.Options.Ttl)
        End If
    End Sub
End Class
Dave Kreskowiak 16-Nov-23 9:16am    
I still cannot replicate the problem on my machine using VB.NET in any application type.

EDIT: ...on either of my machines.

Is the problem with this code only, or any code.

Oh, and "Application.DoEvents" screams you're doing something wrong. You should NEVER be using it unless you are absolutely sure you know exactly how DoEvents works and its impacts.

ftpx 16-Nov-23 10:28am    
First of all, thank you very much for your support effort. Since 15 years I have been actively writing code. The problem is not only in this sample code but in all our projects. This problem has been present since Visual Studio 2022 was first released. That's why we still continue to use VS2019 as a team. Because we do not experience this problem.

I have attached a video to my question to explain the difference between VS2022 and VS2019. You can check that too.

I shortened the code for you, please watch the video on this link.

Problem Video
Dave Kreskowiak 16-Nov-23 15:37pm    
The only difference between what you're doing and what I'm doing is you're dragging the highlight to the new line. I was right-clicking it and picking "Set next statement".

I tried dragging the highlight around like you did and everything worked as expected. I still cannot get it to fail.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900