Sunday 4 November 2012

New Debugger Behavior in Visual Studio 2012

I have a .NET 3.5 library project to debug. To do it I launch it through an external exe compiled with Delphi in native code.
This works great in visual studio 2010 and earlier, I never had any issue of any type.
This doesn't works anymore in visual studio 2012: the debugger doesn't stops, breakpoints are simply ignored.

The key point is that the selection of the target framework under "Application" tab to be .Net 3.5 only affects building the class library project under the current solution. This setting, at least in VS 20102, does not influence what debugger engine type (i.e., .net 4.0? 3.5?) uses to attach to the external program. As a result VS does not know what .Net version the class library being loaded by your external app, and by default assumes .Net 4.0. Unfortunately, .Net 4.0 debug engine does not work on .NET code v3.5 or prior.

Solution #1: Use Debug -> Attach to Process -> Change the debugger type by hitting the "Select..." in the dialog and choosing "Managed (v3.5, v3.0, v2.0) code" -> Choose external exe -> Attach. Now, you are explicitly telling VS you want to use the debug engine for .Net 3.5 or prior.

Solution #2: Make your external app the "Start up project". In Visual Studio, File -> Open -> Project, and select your Delphi app. You have just created a new solution with the delphi binaries as the startup project. If you go to the project properties, you can change the "Debugger Type" from 'Auto' to 'Managed (v3.5, v3.0, v2.0)'. By doing this, you have told Visual Studio explicitly you want to use the debug engine for .Net 3.5 or prior. Now, the breakpoints in your class library code will hit, as long as you maintain having the external delphi app as your startup project and setting the Debugger Type explicitly to use .Net 3.5 or prior.

This is the complete discussion with M$ guys at Microsoft Connect: