Kean Walmsley


  • About the Author
    Kean on Google+

July 2014

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    








« Importing Photosynth point clouds into AutoCAD 2011 - Part 3 | Main | "AutoCAD 2011 New APIs" webcast recording »

April 28, 2010

Hitting breakpoints in .NET Class Libraries while debugging with Visual Studio 2010

This question has popped up a few times since Visual Studio 2010’s recent launch. I received it by email overnight from Roland Cox, which is interesting as I’d already planned this post for today.

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).

I first saw this issue raised a few times on threads with Microsoft, both with respect to AutoCAD and Revit. Jeremy has also posted something on his blog about it.

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).

Solution 1

Start the exe that loads your AddIn (acad.exe, revit.exe, etc) and then attach to it from Visual Studio (Debug -> Attach to Process...)

Solution 2

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:

<startup>

  <supportedRuntime version="v2.0.50727" />

</startup>

Solution 3

Add the exe that loads your AddIn as an existing project to your solution and set the debugger version for it to v2.0.

  1. Right-click the Solution in the Solution Explorer and select Add -> Existing Project... and locate the exe that loads your AddIn

 Add an existing project to our VS 2010 solution

  1. Right-click on the Project that has just been added and select Set as StartUp Project

 Make our new project the startup project

  1. Right-click on the Project and select Properties

 Edit our project's properties

  1. Set the Debugger Type to Managed (v2.0, v1.1, v1.0)

Change the debugger type in our executable project's properties

blog comments powered by Disqus

10 Random Posts