Hitting breakpoints in .NET Class Libraries while debugging with Visual Studio 2010
Do you know how to debug AutoCAD and a custom add in using Visual Studio 2010?
What settings do I need to make? I know the add is getting loaded (the code runs in AutoCAD) but I can't set a breakpoint (it shows a empty circle saying that VS doesn't have the assembly loaded).
Adam Nagy, from our DevTech team in Europe, has created this excellent DevNote on the ADN website covering the various options for dealing with this problem. I’ve used this as the basis for the details in today’s post. (Thanks, Adam! :-)
The problem is not at all specific to Autodesk products, although – if the above threads are an indicator – it does seem that as commonly used .NET plugin hosts our products are among the more common environments in which people are hitting this issue.
The cause of the problem boils down to the fact that VS 2010 does not choose the right version of the debugger for Class Library projects targeting prior versions of the .NET Framework: it always uses the default version, the debugger targeting v4 of the .NET Framework. This debugger doesn’t see breakpoints in projects targeting older versions of .NET.
The three workarounds Adam has highlighted show different ways to make VS 2010 use the correct debugger (one which actually hits breakpoints) on these projects. Which solution works best for you will depend on your specific scenario (I would tend to use option 2 or 3, myself).
Start the exe that loads your AddIn (acad.exe, revit.exe, etc) and then attach to it from Visual Studio (Debug -> Attach to Process...)
Modify the config file of the exe that loads your AddIn (acad.exe.config, revit.exe.config, etc) so that it contains the following just before the </configuration> part:
<supportedRuntime version="v2.0.50727" />
Add the exe that loads your AddIn as an existing project to your solution and set the debugger version for it to v2.0.
- Right-click the Solution in the Solution Explorer and select Add -> Existing Project... and locate the exe that loads your AddIn
- Right-click on the Project that has just been added and select Set as StartUp Project
- Right-click on the Project and select Properties
- Set the Debugger Type to Managed (v2.0, v1.1, v1.0)