Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Advice on debugging C# in Visual Studio

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
Kevin.Bell
12673 Views, 19 Replies

Advice on debugging C# in Visual Studio

Kevin.Bell
Advisor
Advisor

Hi,

 

I've used to coding in Python in Dynamo, but for various reasons am now trying out C# and coding in Visual Studio.

 

I can compile DLLs OK, which run in Revit, but when I hit debug Revit pops up and immediatly exits with the following message in VS:

 

The program '[22680] Revit.exe' has exited with code 0 (0x0).

 

So I cant debug or watch the code execute at all.

 

Is there some setting I'm missing?

 

I'm using Visual Studio and the Add-In wizard for Revit 2015.

 

Thanks.

0 Likes

Advice on debugging C# in Visual Studio

Hi,

 

I've used to coding in Python in Dynamo, but for various reasons am now trying out C# and coding in Visual Studio.

 

I can compile DLLs OK, which run in Revit, but when I hit debug Revit pops up and immediatly exits with the following message in VS:

 

The program '[22680] Revit.exe' has exited with code 0 (0x0).

 

So I cant debug or watch the code execute at all.

 

Is there some setting I'm missing?

 

I'm using Visual Studio and the Add-In wizard for Revit 2015.

 

Thanks.

19 REPLIES 19
Message 2 of 20
stever66
in reply to: Kevin.Bell

stever66
Advisor
Advisor

I assume you can run your code from VS, and you have it set up to start revit, and all that works.

 

I don't think debug works, probably because revit has to start before the code can run.  I think you have to set a breakpoint, then run the code, and use the step commands after the breakpoint is reached.

 

it also seems like there was some compatibility setting that was added to VS around 2015 that has to be set right,, but I can't remember if that made the debug menu work or not.   

0 Likes

I assume you can run your code from VS, and you have it set up to start revit, and all that works.

 

I don't think debug works, probably because revit has to start before the code can run.  I think you have to set a breakpoint, then run the code, and use the step commands after the breakpoint is reached.

 

it also seems like there was some compatibility setting that was added to VS around 2015 that has to be set right,, but I can't remember if that made the debug menu work or not.   

Message 3 of 20
stever66
in reply to: Kevin.Bell

stever66
Advisor
Advisor

My best advice is to learn the differences between getting a program to run with VS, and the sharp develop.

 

do all your troubleshooting in sharp develop ( no starting and constantly restarting revit), and then paste your code to VS.

 

oddly enough, the debug menu doesn't work in sharp either.  Again, you have to set break points, and run the code from the revit macros dialog box.

0 Likes

My best advice is to learn the differences between getting a program to run with VS, and the sharp develop.

 

do all your troubleshooting in sharp develop ( no starting and constantly restarting revit), and then paste your code to VS.

 

oddly enough, the debug menu doesn't work in sharp either.  Again, you have to set break points, and run the code from the revit macros dialog box.

Message 4 of 20

Mustafa.Salaheldin
Collaborator
Collaborator

In Visual Studio enable the "Used Managed Compatibility Mode" option from Tools menu -> Options -> Debugging

 

Used Managed Compatiblity Mode.png

Please don't forget to mark this reply as an answer if it satisfies your needs.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

In Visual Studio enable the "Used Managed Compatibility Mode" option from Tools menu -> Options -> Debugging

 

Used Managed Compatiblity Mode.png

Please don't forget to mark this reply as an answer if it satisfies your needs.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 5 of 20

Kevin.Bell
Advisor
Advisor

OK, I found the answer to this, I have to build my solution then start Revit, once Revit is running I click Debug > Attach to process.

 

This then allows me to set break points and debug my code.

 

I'm unsure why I have to use Attached to process though, I thought it would be automatic...

OK, I found the answer to this, I have to build my solution then start Revit, once Revit is running I click Debug > Attach to process.

 

This then allows me to set break points and debug my code.

 

I'm unsure why I have to use Attached to process though, I thought it would be automatic...

Message 6 of 20

Mustafa.Salaheldin
Collaborator
Collaborator
Accepted solution

No If you follow my solution you don't have to attach process.

From the project properties just browse to the Revit.exe path and it will start Revit, run the addin and allow you to debug.

 

Debug.png


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

No If you follow my solution you don't have to attach process.

From the project properties just browse to the Revit.exe path and it will start Revit, run the addin and allow you to debug.

 

Debug.png


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 7 of 20

Kevin.Bell
Advisor
Advisor

Mustafa - Thanks that worked!

0 Likes

Mustafa - Thanks that worked!

Message 8 of 20

0001des
Enthusiast
Enthusiast

Mustafa,

Your post worked for me as well.  Thanks so much.  I upgraded to Visual Studio 2017, and everything I did failed until I read your post.  The Revit process started, but it kept killing right away.  "Use Managed..." fixed it.

0 Likes

Mustafa,

Your post worked for me as well.  Thanks so much.  I upgraded to Visual Studio 2017, and everything I did failed until I read your post.  The Revit process started, but it kept killing right away.  "Use Managed..." fixed it.

Message 9 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

This solved it for me, thanks!

0 Likes

This solved it for me, thanks!

Message 10 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

i had same problem and it works now... thanks you

so much!!!!!!!!!!!!!!!

0 Likes

i had same problem and it works now... thanks you

so much!!!!!!!!!!!!!!!

Message 11 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

Hi Mustafa, 

 

I followed your instructions enabling the "Used Managed Compatibility Mode" option from Tools menu -> Options -> Debugging. But the yellow debugging arrow still not popping up. It gives the warning at the breakpoint that "The breakpoint will not currently be hit. No symbols have been loaded for this document". I was following step by step in this course https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/lesso.... When I am trying to debug and setting up the breakpoint and then began debugging, the yellow debugging arrow is not showing up. Can you please suggest? Much appreciated. 

 

Liang 

 

 

Yellow debugging arrow not showing upYellow debugging arrow not showing upPointed to Revit.exePointed to Revit.exe

0 Likes

Hi Mustafa, 

 

I followed your instructions enabling the "Used Managed Compatibility Mode" option from Tools menu -> Options -> Debugging. But the yellow debugging arrow still not popping up. It gives the warning at the breakpoint that "The breakpoint will not currently be hit. No symbols have been loaded for this document". I was following step by step in this course https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/lesso.... When I am trying to debug and setting up the breakpoint and then began debugging, the yellow debugging arrow is not showing up. Can you please suggest? Much appreciated. 

 

Liang 

 

 

Yellow debugging arrow not showing upYellow debugging arrow not showing upPointed to Revit.exePointed to Revit.exe

Message 12 of 20
Mustafa.Salaheldin
in reply to: Anonymous

Mustafa.Salaheldin
Collaborator
Collaborator

This is easy, just make sure in the manifest file (.addin file) that you have done 2 things:

1 - you are using the correct full class name (which is the namespace.classname)

2 - you are putting the file path of your complied assembly (something like "path/to/my/visual studio project/bin/debug/myaddin.dll)

 

I hope that solve the problem and is so please don't forget to mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes

This is easy, just make sure in the manifest file (.addin file) that you have done 2 things:

1 - you are using the correct full class name (which is the namespace.classname)

2 - you are putting the file path of your complied assembly (something like "path/to/my/visual studio project/bin/debug/myaddin.dll)

 

I hope that solve the problem and is so please don't forget to mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 13 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

Hi Mustafa, 

 

Thanks for the reply. I checked the .addin file and did not find problems. Please see the screenshot below. The yellow debugging arrow is still not showing up. I think it is more about how to set up configurations to attach visual studio debugging session to the Revit session. We can have a goto meeting if you like. Can you please suggest? Appreciate it. 

 

.addin file.addin file

0 Likes

Hi Mustafa, 

 

Thanks for the reply. I checked the .addin file and did not find problems. Please see the screenshot below. The yellow debugging arrow is still not showing up. I think it is more about how to set up configurations to attach visual studio debugging session to the Revit session. We can have a goto meeting if you like. Can you please suggest? Appreciate it. 

 

.addin file.addin file

Message 14 of 20
Mustafa.Salaheldin
in reply to: Anonymous

Mustafa.Salaheldin
Collaborator
Collaborator

Ok, so one last thing, have you selected debug Managed Code from the debugging settings?

The picture is shown a little bit in the bottom of this topic.(maybe in the second page now) Smiley Happy

 

In Visual Studio enable the "Used Managed Compatibility Mode" option from Tools menu -> Options -> Debugging


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes

Ok, so one last thing, have you selected debug Managed Code from the debugging settings?

The picture is shown a little bit in the bottom of this topic.(maybe in the second page now) Smiley Happy

 

In Visual Studio enable the "Used Managed Compatibility Mode" option from Tools menu -> Options -> Debugging


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 15 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

Hi Mustafa, 

 

Yes I did as shown in the screenshot below. Let me know when we can have a quick goto to look at this. And then I will post what we find here afterwards. 

 

Debugging SettingsDebugging Settings

0 Likes

Hi Mustafa, 

 

Yes I did as shown in the screenshot below. Let me know when we can have a quick goto to look at this. And then I will post what we find here afterwards. 

 

Debugging SettingsDebugging Settings

Message 16 of 20
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Accepted solution

Mustafa is so helpful during the goto meeting and found the issue in the manifest file. On Line 19 below, we changed 34 to any random 2 digits (0-9, a-f). The original AddInId was conflicting with an existing .addin file. After changing 34 to 66, the debugging yellow arrow pops up. 

Mustafa is a magician! Cheers! 

 

 

Manifest  FileManifest File

0 Likes

Mustafa is so helpful during the goto meeting and found the issue in the manifest file. On Line 19 below, we changed 34 to any random 2 digits (0-9, a-f). The original AddInId was conflicting with an existing .addin file. After changing 34 to 66, the debugging yellow arrow pops up. 

Mustafa is a magician! Cheers! 

 

 

Manifest  FileManifest File

Message 17 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

Hi Mustaffa, I set all of these settings. But the external Addin would not appear to show my addon button after Revit lunched. any thought?

0 Likes

Hi Mustaffa, I set all of these settings. But the external Addin would not appear to show my addon button after Revit lunched. any thought?

Message 18 of 20
Mustafa.Salaheldin
in reply to: Anonymous

Mustafa.Salaheldin
Collaborator
Collaborator

Most probably you didn’t copy the manifest file (.addin) to the proper directory. Which path did you use to save your file?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes

Most probably you didn’t copy the manifest file (.addin) to the proper directory. Which path did you use to save your file?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 19 of 20
Anonymous
in reply to: Mustafa.Salaheldin

Anonymous
Not applicable

the  .addin file is generated at my project folder such as (D:\VR\Revit_Addon_Sample\mySample\RevitAddin_Unity1\RevitAddin_Unity1\RevitAddin_Unity1.addin)

0 Likes

the  .addin file is generated at my project folder such as (D:\VR\Revit_Addon_Sample\mySample\RevitAddin_Unity1\RevitAddin_Unity1\RevitAddin_Unity1.addin)

Message 20 of 20
Mustafa.Salaheldin
in reply to: Anonymous

Mustafa.Salaheldin
Collaborator
Collaborator

That is why. Your .addin file must exist in one of the following paths:

  1. %AppData%\Autodesk\Revit\Addins\ – This location is for per-user only, and it is recommended for per-user specific applications.
  2. %ProgramData%\Autodesk\Revit\Addins\ – This location is for multiple users, so all the users can have access to the application.

And don't forget to adjust the path inside the .addin file to properly point to the .dll file from those locations.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes

That is why. Your .addin file must exist in one of the following paths:

  1. %AppData%\Autodesk\Revit\Addins\ – This location is for per-user only, and it is recommended for per-user specific applications.
  2. %ProgramData%\Autodesk\Revit\Addins\ – This location is for multiple users, so all the users can have access to the application.

And don't forget to adjust the path inside the .addin file to properly point to the .dll file from those locations.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report