.net – Visual Studio 2010 Not Debugging .NET 2.0 Code

.netdebuggingvisual-studio-2010windows-xp

Please stick with me, this is a strange one.

Since upgrading from VS2008 to VS2010, some guys at work (and myself) found that we could no longer debug into our code. None of our breakpoints were being hit.

Without giving too much away, my work consists of writing .NET apps which run on top of a custom platform application we’ve developed. These apps are compiled to .NET 2.0. Debugging typically involves setting our platform app's exe as the startup program to debug into, and launching from there.

Interestingly, none of our developers working on Vista/Windows 7 machines had any issue – just the Windows 2003/XP crowd.

Something about the combination of Visual Studio 2010, .NET 2.0, and Windows XP meant that we could no longer debug into our applications.

I have absolutely no idea why this issue should arise only in Windows 2003 and XP machines. Can anyone shed any light?

Best Solution

I've managed to find a workaround, thanks to this post. The issue seems to be that when debugging into code which is invoked from a native exe, Visual Studio will assume you’re debugging in .NET 4.0. Subsequently all your .NET 2.0 code will run, but the debugger won’t hit any of your breakpoints.

The fix is to give the debugger a helpful hint, in the form of a .exe.config file in the directory you’re launching your startup exe from. Something along the lines of:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727" />
  </startup>
</configuration>

This works as a fix, but doesn't actually answer why this happened in the first place.