Thursday, April 15, 2010

[Revit API] – Visual Studio 2010 and Revit API debugging issues

Visual Studio 2010 is now officially out, and it is great! Some excellent new features, the new look is great, and you can drag code windows to different monitors!

I have installed it and have started working on my Revit API tools with it. Straight away I came across a stumbling block. My API code threw an error, but it was not caught in the debugger, and none of my breakpoints were not hit. After some investigation, it seemed that Visual Studio was not attaching to the Revit.exe process as it should. I tried manually attaching to the Revit.exe process and that seemed to work, but this is a bit of a pain, why doesn’t it automatically attach?

I Googled it, and to my surprise, I found a Microsoft Connect support request about this made by a fellow Revit API developer ‘mikecvelide’. He was using Revit 2010 and found the debugger did not attach either. You can see the thread HERE. Microsoft did some investigation and it seems the problem is Visual Studio 2010 is using the .NET 4.0 debugger even though its a 3.5 or 2.0 application (I don’t believe Revit 2011 supports .NET 4.0 applications).

The workaround is this, edit your Revit.exe.config file which is located in the same directory as the Revit.exe and add:

<supportedRuntime version="v2.0.50727" />

Just before the </configuration> part of it. You should then be able to debug fine in Visual Studio 2010.

Note, v.2.0.50727 is the version I have installed, but you can check C:\Windows\Microsoft.NET\Framework for what the last few digits of your v2.0 folder is (even if you are developing for .NET 3.5 you still need to put in the 2.0 version number)


Anonymous said...

Good catch Rod!!
As much as a VS fix would be good. Allowing us to compile .NET4 would be the ideal solution.

karthik dondeti said...

I am still hitting an error "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded".

I did change the revit configuration file but to no luck yet.

Thank you for any help.

Rod Howarth said...

Hi Karthik,

Is your assembly targeting .NET 3.5 or 4.0? I believe Revit only supports 3.5 at the moment

JS said...

Nice post - I just upgraded to VS 2010 and ran into this.


Anonymous said...

good to know. thx for sharing.

Mario Guttman said...

What a great save!! I owe you lunch if we ever meet. Mario Guttman

Anonymous said...

Hi Rod,

I've follow your instruction. But it only debug on main class. Once main class tried to call other class, it stop debugging.

Thank you for your help.

Kathleen said...

Anyone can confirm if Revit 2012 will be supporting .NET4 ?!