Visual Studio 2022 VB.Net not recognizing colon for multiple statements on one line.

RJBreneman 201 Reputation points
2022-09-10T20:35:09.28+00:00

I am upgrading VB.NET projects from VS2015 to VS2022. Many lines use the colon for multiple statements on a single line, like

Try : If MyDb IsNot Nothing Then MyDb.Dispose() Catch : End Try  

This was, and should still be, acceptable per

Statements in Visual Basic | Microsoft Learn where it states, "You can have multiple statements on a single line separated by the colon (:) character."

Instead, I am getting errors like, "'Try' must end with a matching 'End Try'." I couldn't find any setting for this in Tools | Options. Am I missing something?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,649 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,583 questions
{count} votes

Accepted answer
  1. LesHay 7,126 Reputation points
    2022-09-10T21:12:53.497+00:00

    Hi
    This works OK

        Dim MyDb As String = "Freddy"  
        Try : If MyDb IsNot Nothing Then : MyDb = "Brian" : End If : Catch ex As Exception : End Try  
      
    

0 additional answers

Sort by: Most helpful