BUG: COMException getting DocComment of method of generic base class

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2010
Date: August 2011    

When trying to get the EnvDTE80.CodeFunction2.DocComment property of a method of a generic base class, you get a COMException when using C# and Visual Studio 2010. This didn't happen in Visual Studio 2008 or 2005, and it doesn't happen using VB.NET with Visual Studio 2010.

More Information

Steps to reproduce the problem:

  • Create a macro with the following code:
Language: VB.NET   Copy Code Copy Code (IE only)
Sub Macro1()

        Dim derivedCodeClass2 As EnvDTE80.CodeClass2
        Dim baseCodeClass2 As EnvDTE80.CodeClass2
        Dim someMethodOfBaseClass As EnvDTE80.CodeFunction2


            derivedCodeClass2 = CType(DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements.Item(1), EnvDTE80.CodeClass2)

            baseCodeClass2 = CType(derivedCodeClass2.Bases.Item(1), EnvDTE80.CodeClass2)

            someMethodOfBaseClass = CType(baseCodeClass2.Members.Item(1), EnvDTE80.CodeFunction2)


        Catch ex As Exception


        End Try

End Sub
  • Create a C# project with Visual Studio 2010 and paste this code in the Class1.cs file:
Language: C#   Copy Code Copy Code (IE only)
public class DerivedClass: BaseClass<int>

public class BaseClass<T>
   /// <summary>
   /// SomeMethod()
   /// </summary>
   public virtual void SomeMethod()
  • Execute the macro when the Class1.cs file is active. You get a "System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component".

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