The strange case of InvalidComObjectException exiting Visual Studio 2013 after debugging extension

January 23, 2014

I found a couple of days ago a bug that I hadn’t seen before: when you create an add-in with Visual Studio 2013 (you need to install the VS 2013 SDK), hit F5 to debug it, which launches a second VS 2013 instance and close this instance (even without loading the add-in), you get:

An unhandled exception of type ‘System.Runtime.InteropServices.InvalidComObjectException’ occurred in mscorlib.dll
Additional information: COM object that has been separated from its underlying RCW cannot be used.


This exception happens in System.Threading.Tasks.AsyncCausalityTracer.TraceSynchronousWorkCompletion(System.Threading.Tasks.CausalityTraceLevel, System.Threading.Tasks.CausalitySynchronousWork)

Searching the web I have found that it happens also with packages and DSL designers of the VS 2013 SDK, that is, with any kind of extension. It was reported on Microsoft Connect:

Visual Studio 2013 Domain Specific Language Designer crash on exit.

and Ryan Molden (MSFT) acknowledged the bug in this thread of the MSDN VSX forum about packages:

Default VSPackage template in VS2013 SDK Throws Exception when exiting

It is a bug of the async causality tracing stuff of the CLR 4 modified by the .NET Framework 4.5.1 (and used by VS 2013), because it didn’t happen with the CLR 4 of the .NET Framework 4.5 (used by VS 2012). Notice that it doesn’t depend on the .NET Framework used by your extension (.NET 2.0 in my case).

We will need to live with this bug until the Windows team (which owns the CLR, not the VS team) fixes it. An interesting thing is that I hadn’t seen this problem until I reformatted my laptop with Windows 8.1 a couple of days ago. Previously I was using Windows 7 and in fact I haven’t been able to reproduce the problem today on another laptop with Windows 7.

The strange case of error "Windows Program Compatibility mode is on." when installing Visual Studio 2012 language packs

January 20, 2014

Another problem apart from this other one that can happen installing Visual Studio 2012 language packs to try your extension with other languages is the following:

“Windows Program Compatibility mode is on. Turn it off and the try Setup again”


The error message is misleading: I have found that it happens if you rename the setup file from the original name “vs_langpack.exe” to something else, such as “vs_langpack_english.exe”, etc. (for example, to have all the language packs in the same folder).


  • The problem doesn’t happen with Visual Studio 2013 language packs, though.
  • I am using Windows 8.1 RTM. It could be that the problem doesn’t happen on other Windows versions.
  • Apparently the same happens to VS 2012 (not a language pack) if not named correctly, according to this bug report on Microsoft Connect. Microsoft says it’s a bug of Windows 8.1 RTM.

11th Microsoft Most Valuable Professional (MVP) title

January 2, 2014

Happy New Year!

Microsoft awarded me yesterday my 11th Most Valuable Professional (MVP) title, which, as always, makes great the start of the new year :-).

Speaking about the new year, I want to share some of my plans in the Visual Studio extensibility area:

I would be very satisfied if I can accomplish all that 🙂

Microsoft Office Language Packs

December 21, 2013

In the same way that Visual Studio offers language packs to have multiple languages, which is really handy for developers of VS add-ins, Microsoft Office 2010 and higher also provides language packs, although not for free:

Microsoft Office 2010 Language Packs

Microsoft Office 2013 Language Packs

which are also handy for developers of add-ins for the VBA editor, to discover, for example, that the “Standard” commandbar name is localized (“Estándar” in Spanish), when it shouldn’t.

To change the language of Office you have to go to Start, All Programs, Microsoft Office, Microsoft Office 2010 Tools, Microsoft Office 2010 Language Preferences. Programmatically, you can get the language of Office through the registry key HKEY_CURRENT_USER\Software\Microsoft\Office\<version>\Common\LanguageResources, UILanguage name.

Error "The language is already installed." installing Visual Studio language packs

December 18, 2013

As I explained in the following article:

HOWTO: Testing add-ins in localized versions of Visual Studio

Visual Studio 2012 and higher allows to install additional languages (“Tools”, “Options” window, “Environment”, “International Settings” section) through language packs, rather than installing localized full versions of Visual Studio (as in previous versions):

Microsoft Visual Studio 2012 Language Pack

Microsoft Visual Studio 2013 Language Pack

When selecting a language other than English, you may find running the downloaded vs_langpack.exe setup the following error:

“The language pack is already installed. To install an additional language, please install the language pack for that language”


The problem is happening because you are actually installing the English language pack on an English Visual Studio (notice the title 2013 Language Pack – ENU). It happens that those download pages need some long seconds since you select a language in the dropdown list until the page is refreshed with the corresponding downloadable setup. If you click the “Download” button just after selecting a language in the dropdown list, you actually download the (original) English language pack. Once the page is refreshed, the whole page is localized (including the “Download” button) and then you can download the correct vs_langpack.exe setup.

Notice the amount of unfortunate events in this scenario that can confuse many people:

  • The page needs many seconds to switch the language – a bad design -.
  • No clear indication is provided to the user. The Download button is still visible and enabled.
  • The downloaded setup has the same name “vs_langpack.exe” that doesn’t include the language.
  • The setup error doesn’t say the language that you are trying to install (only the title states the “ENU” language).

How to create a solution folder inside another solution folder

December 3, 2013

Today I have received an e-mail asking if there is a workaround to the problem that I explained in the post PRB: NotImplementedException adding a solution folder to a solution folder in Visual Studio from a macro or add-in.

I hadn’t updated the post yet until today but I already hinted the solution in this other post: HOWTO: Create a project from a Visual Studio add-in inside a solution folder

The trick is to cast the EnvDTE.Project.Object property to the EnvDTE80.SolutionFolder type introduced by VS 2005.

Here it is a sample code:

Sub AddNestedFoldersToSolution()

   Dim sol2 As EnvDTE80.Solution2
   Dim solFolderProject1 As EnvDTE.Project
   Dim solFolderProject2 As EnvDTE.Project
   Dim solFolder As EnvDTE80.SolutionFolder

   sol2 = CType(DTE.Solution, EnvDTE80.Solution2)

   solFolderProject1 = sol2.AddSolutionFolder("Folder 1")

   solFolder = CType(solFolderProject1.Object, EnvDTE80.SolutionFolder)

   solFolderProject2 = solFolder.AddSolutionFolder("Folder 2")

End Sub

Add-ins officially deprecated in Visual Studio 2013

October 31, 2013

Add-ins for Visual Studio have become so irrelevant for Microsoft that apparently they don’t even deserve a post in the Visual Studio blog to announce that they are officially deprecated in Visual Studio 2013. So I only became aware through this thread in the MSDN VSX forum that points to this MSDN documentation:

Automation and Extensibility for Visual Studio

that states:

“Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions.”

That means that at some point the Add-In Manager will be removed from Visual Studio. This was expected as I posted here and I have already planned to move my MZ-Tools add-in to a package as I announced here, along with a new series of articles about creating packages (next year) once I learn the stuff more deeply.

VS 2013 SDK and Shell download links

October 25, 2013

I have updated the page Resources about Visual Studio .NET extensibility to include the download links to:

  • Visual Studio 2013 SDK
  • Visual Studio 2013 Isolated Shell
  • Visual Studio 2013 Integrated Shell

and to include the link to the Visual Studio 2013 SDK MSDN documentation.

Remember that the VS 2013 SDK is now required to get the template for add-ins, as I explained here.


The strange case of error "Subscript out of range" in Data View starting VB 6

September 19, 2013

I am writing this little post mainly for myself in the future and the other two users that seem to have experienced this in the past. I already saw this in the past but until today I didn’t find out how to fix it:

If you get a msgbox error with the title “Data View” and the text “Subscript out of range” starting Visual Basic 6.0, it means that your commandbars are corrupted and need resetting:

  • Right-click on any toolbar and select “Customize…” menu entry.
  • For each toolbar in the list, click the “Reset…” button.

How did I find this fix? After using SysInternals Process Monitor for a while, I only discovered that Data View is actually a kind of hidden add-in. It doesn’t appear in the Add-In Manager, but it has a Connect class, a toolwindow, etc. The clue was that right-clicking on the treeview of its toolwindow, another error “91 : object variable or with block variable not set” happened and the toolwindow was crashed. And what happens typically when you right-click a treeview node? A commandbar is shown! If the commandbar is not shown, it means that there is a problem with the commandbar subsystem (quite typical of VB6), so I tried resetting the commandbars as explained above and bingo!

MZ-Tools Articles Series: HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package

July 18, 2013

Two extension approaches (add-in, packages), two APIs (automation model, services)… and four combinations:

It happens that add-ins not only can use its more natural API (the EnvDTE automation model), but can also use services provided by the Visual Studio shell and packages. The EnvDTE automation model doesn’t provide a direct way to get a service but you can do it as I explained long time ago in this article:

HOWTO: Get a Visual Studio service from an add-in

And packages not only can use its more natural API (services), but can also use the EnvDTE automation model. In fact, the EnvDTE*.* reference dlls are added by default to VS Package projects!. Getting the DTE instance from a package is not difficult except for a little detail: if the package is marked to load on startup (autoload), rather than using delayed loading, it can happen that the IDE is not initialized yet and the package can’t get the DTE instance. This IDE initialization problem happens also with add-ins, which have an OnStartupComplete method and therefore there is pattern to initialize correctly an add-in. Alas, packages need to use a more complicated pattern to get notified when the IDE is fully initialized, with a trick that Microsoft explained originally in this post:

Dr. eX: Why does GetService(typeof(EnvDTE.DTE)) return null?

Since I found the code of the package class somewhat dirtied with that approach, I have rewritten it with a more clean approach (using a separate class for the task):

HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package