Addin Does Not Work When Not Debugging Through Visual Studio

Addin Does Not Work When Not Debugging Through Visual Studio

kristian_oa
Enthusiast Enthusiast
798 Views
5 Replies
Message 1 of 6

Addin Does Not Work When Not Debugging Through Visual Studio

kristian_oa
Enthusiast
Enthusiast

Hello,

 

I am writing an addin for Inventor 2025 in C# (.Net 8.0) through Visual Studio and am encountering an issue when attempting to load the addin on my own (or another computer) without using Visual Studio.

 

When I launch Inventor through Visual Studio and build the addin, it loads as intended, with my custom ribbon tabs and other functions working.

 

However, if I launch Inventor normally with the built addin in the addins folder, the ribbon tab will appear with all buttons and their icons, but if click on the tab it disappears shortly after and seems to unload the addin.

 

The paths I have tried placing my addin in are:

  • C:\Program Files\Autodesk\Inventor 2025\Bin\Addins
  • C:\ProgramData\Autodesk\Inventor Addins
  • C:\Users\%USERPROFILE%\AppData\Roaming\Autodesk\Inventor 2025\Addins

All of these paths worked when debugging the addin through Visual Studio.

 

Going into the Addin settings to load my addin does nothing. 

 

Is there something I have potentially missed or am misunderstanding about building addins for Inventor? I also used Inventor's provided C# template for Inventor 2025 to build the addin.

 

 

0 Likes
Accepted solutions (1)
799 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor

The fact that the buttons are successfully loaded, means your add-in is being initialized correctly.

However, I suspect that the issue occurs when you click one of the buttons, likely due to an error in the code that runs on execution. You probably have a function that handles the button click, something like:

Private Sub MyButton_OnExecute(Context As NameValueMap)
    Try
        ' Your code here
    Catch ex As Exception
        MsgBox("Something went wrong: " & ex.Message)
    End Try
End Sub

Could you check whether you have a Try/Catch block around all the code in that function? If not, adding one might help catch and display the error, making it easier to debug.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 6

TylerWarner33
Advocate
Advocate

C# Version would look like this:

private void YourButton_OnExecute(NameValueMap context)
{
	try
	{
		// Your code here.
	}
	catch (Exception ex)
	{
		MessageBox.Show($"Exception.{System.Environment.NewLine}Message: {ex.Message}.{System.Environment.NewLine}StackTrace: {ex.StackTrace}.");
	}
}

 
I agree with Jelte, something is breaking in the add-in code. Are you copying all of the reference assemblies that your add-in uses when providing it to another user? The entire folder with all files should look the same on your computer when running from Visual Studio & another user when running from Inventor.

If this answered your question, click 'Accept Solution'.
If this was helpful, click 'Like'.

Tyler Warner

0 Likes
Message 4 of 6

kristian_oa
Enthusiast
Enthusiast

Hi Jelte,

 

Thanks for your repsonse. You were right that there was an error somehwere in my code, in which it only ever triggered while not running through Visual Studio.

 

I always try to avoid Try Catch where I can so when they occurr I can define explicit rules and operations to handle those situations. However, in this case, the issue was because my code creates a config file to store settings for the Addin the user can configure, which was not being read when not running through VS.

 

I currently have these settings stored as an XML file in a directory named "config" wihtin the addin's folder. When launching the addin through VS, it sets the current working directory from within my addin to "C:\ProgramData\Autodesk\Inventor Addins\MyAddinName", however launching it without VS sets the current directory to "C:\Program Files\Autodesk\Inventor 2025\bin".

Despite the difference in paths, my addin is still loaded from the former path and nothing is in the latter path (aside from the default Inventor .addin files).

 

Are you aware of any native ways to store addin configuration settings within Inventor, or a way to always get Inventor's default addin directory (without hard-coding a value that might change in future releases) of Inventor? E.g. is there something like "Inventor.GetInstallPath()" which would return the current install location of Inventor, no matter the version (2024, 2025, etc)?

0 Likes
Message 5 of 6

kristian_oa
Enthusiast
Enthusiast

Hi Tyler,

 

Thanks for your reply. All my references are being copied, including any NuGet packages I used.

 

The problem was indeed an error in my code which only every occurred when not running through Visual Studio due to VS setting the current working directory of Inventor's execution to the path of my addin, whereas launching it normally without VS would set the current directory to Inventor's install path. I need to get the crrent directory as I am reading/writing to a config file that the user can set to modify certain options in the addin.

 

I will need to find a local place to store the config that is variable across machines, probably the user's %AppData% might work.

0 Likes
Message 6 of 6

TylerWarner33
Advocate
Advocate
Accepted solution

There are a few places that your add-in can be stored, depending on your goal & those can be found in the documentation. Some are version dependent, some are version independent. There is usually a 'target' added to the Visual Studio project file (at the end) to copy outputs to one of those folders. That folder is what Inventor will load for the add-in.

TylerWarner33_0-1761559177263.png

 

I have stored configuration within the add-in folder or within the 'AppData' folder, depending on the goal & situation.

string exePath = Assembly.GetExecutingAssembly().Location;
string exeDirectory = Path.GetDirectoryName(exePath);
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

 

If this answered your question, click 'Accept Solution'.
If this was helpful, click 'Like'.

Tyler Warner

0 Likes