Run and debug Add-ins


Add-ins are based on .NET Framework thus, you can use C#, C++/CLI, or VB.NET language to develop the Add-ins application. NET assemblies dll once loaded cannot be unloaded like in the case of  Native Code. So, if we modify the source code of the .NET program to reproduce the build, we must first close the MicroStation that already has this assembly loaded. Below we introduce Add-in debugging. There are two ways to Add-in debugging, one is to start MicroStation through VS to debug, the other is to attach VS to the already started MicroStation process for debugging. Let's introduce the first method step by step below:

  1. Open your project in VS. In the Debug category of the project properties, set the Start external program to point to your MicroStation CE microstation.exe and enter test.dgn in the Command line argument field. Note that this step belongs to the project setup and only needs to be done once for a project.

2. Find the CreateElement.LineAndLineString1() line of MyAddins.cs in the source code window of VS, and click on the blank space at the front of the line to set the line as a breakpointAn orange round button will appear in the forefront of this row, and the code content of this row will also be highlighted. As shown below:

3. Click the run button (the green arrow in the figure below) in the VS debugging toolbar to start Mstn. After Mstn is started, type MDL LOAD csAddins in the input field and press Enter. The program will run to the breakpoint and pause. As shown below:

4. There are many tools available on the debugging toolbar, such as Step Into in the red frame and Step Over in the blue frame. If you can't find this toolbar, please select VS menu View> Toolbars> DebugNow let us click the Step Into tool to enter the LineAndLineString1 method of CreateElement.cs.

5. At this time, you can move the mouse cursor to a variable, and the value of the variable will appear. 

6. Click the Stop Debugging button on the debugging toolbar to stop debugging, and Mstn started by VS will also be automatically closed. VS also provides a large number of rich debugging commands and methods. You can find materials that specifically introduce the use of VS to learn VS's debugging technology in depth.

Here is another way to debug MicroStation Add-ins. This method does not require you to configure the Debug page in the project properties in advance.The steps are as follows:

1. Start MicroStation.

2. Set a breakpoint on the CreateElement.LineAndLineString1() line of CsAddin.cs. For detailed operation, see step 2 in the first debugging method.

3. In the VS menu select Debug > Attach to Process, find and select the microstation.exe in the process list that pops up in the Connect to Process dialog box (Operational Tips: You can use the mouse to click on the list The Head Process causes the processes to be sorted in descending order so that microstation.exe can be found quickly. Click the Select button to bring up the following dialog box, select the Managed (v4.6, v4.5, v4.0) option and click the Attach button.

  1. Switch back to MicroStation, type MDL LOAD csAddins and press Enter. At this point, you enter the program debugging state. The specific debugging method is the same as the first debugging method described above. See step 4 and step 1 of the first debugging method.

Prev:[[Creating Elements in Add-in]]Next:[[Adding Commands to Add-ins]]