Debugger not working

 

Problem Description
================

When you try to debug a simple windows application in Visual Studio 2005, you get the following error :

----------------------------------
Microsoft Visual Studio
----------------------------------
Unable to start program '<application_name>'.A debugger dll, msdbg2.dll, is not correctly installed. Please repair your Visual Studio installation via 'Add or Remove Programs' in control panel.

If the problem persists, you can manually register msdbg2.dll from the command prompt with 'regsvr32 "%CommonProgramFiles%\Microsoft Shared\VS7Debug\msdbg.dll"'.
----------------------------------
OK  
----------------------------------

 

Diagnostic
=======

We can use Debugger Diagnostic Tool to find out any error about this :

This Tool is available at :

https://download.microsoft.com/download/a/6/f/a6f1de85-7284-4c97-9ddd-6f18000f5848/DebuggerDiagnostics.msi

In order to simulate the problem, i tried to rename the msdbg2.dll file on my system and then run the DebuggerDiagnostic tool. The output that i get on my system is the following :

C:\Documents and Settings\prabhatt\My Documents\MSDN\Debugger Diagnostics>DebuggerDiagnostics.exe

Begin 'CheckMDMImage()'
mdm.exe: version '7.10.3077' with hash '{6607858A-7B579EC3-E062DAB3-BF891368-CBF1CB9C}'.
Result of 'CheckMDMImage()' is '00000000'

Begin 'CheckMSDBG2Image()'
Could not calculate hash for 'msdbg2.dll' - 0x80070002
Result of 'CheckMSDBG2Image()' is '80070002'

...

Begin 'CoCreateMachineDebugManager(&spMachine)'
Result of 'CoCreateMachineDebugManager(&spMachine)' is '8007007e'

 

Analysing the report
===============

We found that the following portion is reporting some error :

Begin 'CheckMSDBG2Image()'
Could not calculate hash for 'msdbg2.dll' - 0x80070002
Result of 'CheckMSDBG2Image()' is '80070002'

It states that it is unable to calculate the HASH value of the msdbg2.dll. Which indicates that there might be some problem with this DLL.

 

Root Cause
=======

There are three causes of this issue :-
1. The dll is not present physically at the specified path.
2. The dll is corrupted due to some unknown reason.
3. The dll is not the original one that comes with Visual Studio.

 

Conflict/Corrupt or missing msdbg2.dll
=======================

Once we identify that there are some issues with this dll, lets start identifying what might be the reason.

1. Manually search for the file in the directory C:\Program Files\Common Files\Microsoft Shared\VS7Debug

Is the file present there? If no we need to install the file there and register it properly.

There are several public sites from where we can download, install and register it. Since these sites might not be safe. I would recommend you to try installing the files from the installation disks of Visual Studio that you have.

2. If the file is physically present there, then it might be corrupted. So go ahead and install the new file from the installation disk and register it.

3. One interesting thing is that Office XP installation and Office XP update KB833858 also contain the same file msdbg2.dll. So if by any chance, if this file is installed by accident to the directory(C:\Program Files\Common Files\Microsoft Shared\VS7Debug) then also we may get this issue. We can verify this by checking the version, the file that comes with Visual Studio 2005 has the version 8.0.50727.42. On the other hand the file that comes with Office XP update (KB833858) has the version 7.0.9466.0. If this is the case unregister the dll. Install the original one and register it.

 

How to Unregister a dll
==============

1. Start->Run->cmd.
2. At a command prompt, type the following command:
regsvr32 /u <path_of_msdbg2.dll>\msdbg2.dll 

 

How to Register a dll
=============

1. Start->Run->cmd.
2. At a command prompt, type the following command:
regsvr32 <path_of_msdbg2.dll>\msdbg2.dll