More on PRB: “Could not copy temporary files to the output directory” when running add-in project

Three years ago I wrote the article PRB: ‘Could not copy temporary files to the output directory’ error building Visual Studio .NET add-in explaining the common cause for that error when running an add-in project.

There is a second cause that happens when you have a dead devenv.exe process, which can happen from time to time while debugging add-ins, interrupting abruptly the debugging session, entering the computer in sleep mode or something else that I can’t determine for sure, but the fact is that you end with two devenv.exe instances in memory, a visible one with your add-in project and a hidden one locking the DLL. Since this second one doesn’t have a visible window, you have to use the Processes tab of the Task Manager to see it. And of course, you want to kill it, but how do you know which devenv.exe process to kill? The Task Manager of Windows is not of much help, but you can use the much more powerful Process Explorer utility from the former SysInternals (now owned by Microsoft and provided through Microsoft TechNet):

http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

With Process Explorer, which can replace the Task Manager when pressing Ctrl+Alt+Del and clicking the Task Manager button (Options, Replace Task Manager menu) you can right-click a devenv.exe process and select the “Bring to Front” menu. If the main IDE window brings to front, you know that the devenv.exe process is active. Otherwise, it is a dead one and you can kill it. Before using Process Explorer, I always had to choose randomly and I almost ended killing the wrong one.

MZ-Tools Articles Series: HOWTO: Retrieve the Command that created a CommandBarControl from a Visual Studio add-in or macro

The question “How do I retrieve a Command from a CommandBarControl?” has been posted in the forums at least a couple of times and my answer always was “It’s not possible” because the CommandBarControl lacks a Command property, which is the intuitive thing that one would think. It was not until today that I realized that MS provided a way, although far from intuitive:

HOWTO: Retrieve the Command that created a CommandBarControl from a Visual Studio add-in or macro
http://www.mztools.com/articles/2008/MZ2008021.aspx

HOTFIX: A command-line add-in does not load when you start the Visual Studio 2005 IDE

Quite a few months ago I published a post that became quite popular about the Frustrations with command-line add-ins for Visual Studio, where it was mentioned a bug in the Visual Studio 2005 IDE which didn’t loaded command-line add-ins. Today I have found that Microsoft released a hotfix for this problem:

FIX: A command-line add-in does not load when you start the Visual Studio 2005 IDE
http://support.microsoft.com/kb/934517

While it would have been better not to introduce this bug in VS 2005 SP1, it is nice that Microsoft fixed it after SP1 and the patch for Windows Vista, when VS 2008 was about to be released. It is also very very nice that you can download hotfixes without calling MS Support Services.

Now, the funny thing: the KB article says that this hotfix introduces an incompatibility with the XBox 360 SDK. It’s a good thing that I am in the Sony PS3 / PSP camp 😉

BTW, I found this hotfix while searching the list of hotfixes for Visual Studio trying to solve a very nasty problem with the VBC compiler (VB.NET) of VS 2008 that is crashing. It’s nice to see that there is a growing list of hotfixes, although none for my problem (it seems). UPDATE (8 August, 2008): I narrowed the problem to a custom attribute applied to a property and seeing the list of fixes of VS 2008 SP1 beta for VB.NET it mentions Connect ID 322131: “An application that contains a custom attribute causes the compiler to crash” so hopefully that’s my fix 🙂

Rant about EnvDTE.CodeTypeRef.Rank

When you have a variable (EnvDTE.CodeVariable) or function (EnvDTE.CodeFunction), their Type property returns an EnvDTE.CodeTypeRef with information about the type. If the type is an array then CodeTypeRef.Rank returns the dimensions (1, 2…). The problem is that if it is not an array, it throwns an exception, which can hurt the performance if you do that with lots of functions or variables (think an operation that processes the whole code of a solution). It would be much more better if the automation model returns 0 for the Rank if the type is not an array, but chances of MS changing that at this point are minimal, so as a workaround, you should try to call the Rank property only if you know in advance that it is an array (and therefore it is not going to throw an exception). You can know using the CodeTypeRef.AsString property: if the result contains “(” for VB.NET or “[” for C#, you know it is an array.

MZ-Tools Articles Series: HOWTO: Get Microsoft Office bitmaps for Visual Studio add-ins

I have been struggling during the last weeks to get 32×32 icons from Office 2007 and yesterday I found the 2007 Office System Add-In: Icons Gallery. Also, a question that appears from time to time in the forums is how to get the numerical indexes of the Office bitmaps to use when calling the AddNamedCommand method, and incredible as it is, I think that Microsoft never documented this for that method in MSDN, and there used to be years ago an Excel spreadsheet (quite difficult to find then, and impossible nowadays, likely removed from MSDN) to help in the task with VB5/VB6/Office add-ins. Fortunately I put a copy in the Files section of the Yahoo forum for VS.NET add-ins that I used to visit until a couple of years ago before moving to the MSDN forum, and I had a copy of the Excel file in my own hard disk. I have documented all this in my latest article:

HOWTO: Get Microsoft Office bitmaps for Visual Studio add-ins
http://www.mztools.com/articles/2008/MZ2008020.aspx

MZ-Tools Articles Series: HOWTO: Handling buttons and toolbars user customizations from a Visual Studio add-in

Visual Studio allows a rich customization of its user interface and, alas, it can affect your add-in. This new article of mine examines some common customization scenarios and how your add-in can handle them more or less gracefully:

HOWTO: Handling buttons and toolbars user customizations from a Visual Studio add-in
http://www.mztools.com/articles/2008/MZ2008019.aspx

The strange case of System.BadImageFormatException: Could not load file or assembly ‘Microsoft.mshtml’

A couple of days ago another customer of my MZ-Tools add-in reported this exception:

“System.BadImageFormatException: Could not load file or assembly ‘Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The module was expected to contain an assembly manifest.”

The GAC (C:\Windows\Assembly folder) showed the file with the correct version and public key token, so what could it be?

As you may know, what you see in the Windows Explorer when you go to the C:\Windows\Assembly folder is not exactly the contents of that folder but a shell, and fortunately I am old enough to know the old MS-DOS commands to see the actual contents of a folder:

  • Click the Start, Run… menu
  • Type CMD and enter to open a MS-DOS window
  • Type CD C:\Windows\Assembly (CD stands for Change Directory)
  • Type DIR to list the contents
  • Type CD GAC
  • Type DIR to list the contents
  • Type CD Microsoft.MSHtml
  • Type DIR to list the contents
  • Type CD 7.0.3300.0__b03f5f7f11d50a3a
  • Type DIR to list the contents
  • You should get something like (it is in Spanish but I have marked in bold the relevant information):

El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 88B8-2ADF

Directorio de C:\WINDOWS\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a

22/11/2007  11:16    <DIR>          .
22/11/2007  11:16    <DIR>          ..
22/11/2007  11:08         8.007.680 Microsoft.mshtml.dll
22/11/2007  11:16               207 __AssemblyInfo__.ini
2 archivos      8.007.887 bytes
2 dirs  16.842.235.904 bytes libres

So, the size of Microsoft.mshtml.dll should be 8.007.680 bytes, but for the customer was 0 bytes, so there was a file corruption. A repair of Visual Studio didn’t solve the problem so he had to delete the file with the command DEL Microsoft.mshtml.dll and then with a good copy of the file install it in the GAC (you can use the gacutil.exe command-line utility or drag and drop the file using the Windows Explorer).

The strange case of Package ‘Visual Studio Explorers and Designers Package’ has failed to load properly

I was getting the error “Package ‘Visual Studio Explorers and Designers Package’ has failed to load properly” when working with add-ins in VS 2008 since a couple of days ago, along with “COM object that has been separated from its underlying RCW cannot be used” some other times. While I had seen the second error working with add-ins, I had never seen the first one. Browsing the MSDN Visual Studio Extensibility forum today I discovered that I was not the only one, and that the culprit is the Microsoft Source Analysis for C# tool that I installed a couple of days ago, when problems started 🙂

MZ-Tools Articles Series: INFO: List of known project type Guids

I have been struggling during the last day to get a list of actual project type Guids (EnvDTE.Project.Kind property), since not all the Guids that appear in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<version>\Projects registry key are actual project type Guids that appear in project or solution files. Here is the result list:

INFO: List of known project type Guids
http://www.mztools.com/Articles/2008/MZ2008017.aspx

VS SDK, packages, add-ins, macros and more…