BUG: EnvDTE.CodeElement.GetStartPoint(vsCMPart.vsCMPartBody) returns wrong result for VB.NET classes using the Implements or Inherits clauses

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: July 2009   Microsoft Visual Studio 2008


When a class created in a VB.NET project uses the Implements or Inherits clauses, the EnvDTE.CodeElement.GetStartPoint method returns a wrong result when using vsCMPart.vsCMPartBody.

More Information

Steps to reproduce the problem:

  • Create a class with this code:
Language: VB.NET   Copy Code Copy Code (IE only)
1 Public Class C1
2    Public Event Event1()
3 End Class
5 Public Class C2
6    Inherits System.Object
7    Public Event Event1()
8 End Class
  • Create and execute this macro:
Language: VB.NET   Copy Code Copy Code (IE only)
Sub Macro1()

   Dim codeElement As CodeElement

   For Each codeElement In DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements
      MsgBox(codeElement.Name & ": " & codeElement.GetStartPoint(vsCMPart.vsCMPartBody).Line)

End Sub

For the first class the result line is 2 (correct) but for the second class the result line is 8 when it should be 7. This is a bug of Visual Studio 2005 and 2008. It didn't happen in Visual Studio .NET 2003.

Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)