MicroStation Add-ins are .NET assemblies that run inside the MicroStation process. Unlike native DLLs, a .NET assembly cannot be unloaded once it has been loaded into MicroStation.
This is an important difference between .NET Add-ins and native applications:
Because of this, whenever you make changes to your Add-in code and need to rebuild the project, you must first close MicroStation if it is already using the Add-in.
Two Ways to Debug an Add-in
There are two common ways to debug a MicroStation Add-in:
The first method is recommended when developing and testing your Add-in.
Step 1: Configure the Project
Open your project in Visual Studio.
In the project properties:
C:\Program Files\Bentley\MicroStation 2026\MicroStation\microstation.exe
D:\elements.dgn
Note: This configuration only needs to be completed once for each project.
The following image shows an example configuration.
Step 2: Set a Breakpoint
Open MyAddins.cs and locate the following method call:
CreateElement.LineAndLineString1 ();
Click in the left margin next to the line number to set a breakpoint.
When a breakpoint is set:
This tells Visual Studio to pause execution when the code reaches that location.
Step 3: Start Debugging
Click the Start Debugging button (the green arrow) on the Visual Studio toolbar.
Visual Studio will launch MicroStation.
Once MicroStation starts:
MDL LOAD csAddins2
When execution reaches the breakpoint, Visual Studio will automatically pause the program.
Step 4: Step Through the Code
The Visual Studio Debug toolbar provides several useful commands, including:
If the Debug toolbar is not visible, enable it from:
View > Toolbars > Debug
Click Step Into to enter the LineAndLineString1() method in CreateElement.cs.
Step 5: Inspect Variables
While debugging, move the mouse pointer over a variable.
Visual Studio will display:
This feature is useful for understanding program behaviour and verifying that values are correct.
Step 6: Stop Debugging
To end the debugging session:
Visual Studio provides many additional debugging tools, such as Watches, Call Stack, Immediate Window, and Conditional Breakpoints. These advanced topics are outside the scope of this tutorial but are worth exploring as you become more familiar with Visual Studio.
This method is useful when MicroStation is already running and you want to debug your Add-in without launching a new session from Visual Studio.
Unlike Method 1, no special Debug configuration is required.
Step 1: Start MicroStation
Launch MicroStation normally.
Step 2: Set a Breakpoint
In Visual Studio, set a breakpoint in:
CreateElement.LineAndLineString1 ();
For detailed instructions, refer to Step 2 of Method 1.
Step 3: Attach Visual Studio to MicroStation
In Visual Studio:
Managed (.NET Framework 4.x)
Step 4: Load the Add-in
Switch back to MicroStation and enter:
MDL LOAD csAddins2
Press Enter.
When the breakpoint is reached, Visual Studio will pause execution and enter debugging mode.
Step 5: Debug the Add-in
Once Visual Studio breaks at the breakpoint, you can use the same debugging tools described in Method 1: