The Visual Studio debugger can be automatically launched and attached to the service process when theSystem.
method is called. Since this approach entails less work, it's highly recommended to adopt it to debug your extension if your server and IDE are installed on the same machine.
To start debugging at the initialization phase, which is the first phase in the life cycle of an extension, do the following:
-
Run Visual Studio as Administrator and open the SOE or SOI project.
-
Place the following line of code as the first line of your SOE or SOI's
Init()
function:Use dark colors for code blocks Copy public void Init(IServerObjectHelper pSOH) { System.Diagnostics.Debugger.Launch(); //... }
-
Place a breakpoint in your extension code where you want to pause.
-
Build the project in Debug mode. Keep the project open when performing the remainder of these steps.
-
Deploy the updated .soe file in ArcGIS Server Manager and enable the extension with a service.
-
Once the service is restarted, the
System.
method is called, which activates the Visual Studio debugger.Diagnostics. Debugger. Launch() Note that for shared instances, starting the service will not trigger the
System.
method. After the service is started, you must send requests that will come through the extension to trigger the extension'sDiagnostics. Debugger. Launch() Init()
method andSystem.
method (see more details at life cycle of extensions using shared instances). To learn more about using extensions with shared instances, refer to Work with shared instances.Diagnostics. Debugger. Launch() The following Visual Studio Just-In-Time Debugger dialog box will pop up automatically.
Click Yes, debug ArcSOC.exe.
Note: If you don't see the Just-In-Time Debugger prompt, make sure you select the Just-In-Time debugger option when you install Visual Studio.
-
Choose the project to be debugged and click OK.
Then click Attach when the Attach Security Warning dialog box appears.
If you can't find the project listed in Available Debuggers, it’s likely that your project is not opened in Visual Studio in Administrator mode. You can run Visual Studio as an Administrator and load the project to start over.
-
The debugger launches and automatically pauses at
System.
instantly, and you can debug theDiagnostics. Debugger. Launch() Init()
function now. -
You can also perform certain service operations to trigger the breakpoints and step through the code as you normally would.
Stopping the service will trigger the extension's
Shutdown()
method. For dedicated instance, the debug session will be automatically terminated once theShutdown()
method finishes executing. For shared instances, afterShutdown()
method finishes executing, the debug session is still active, waiting for the next breakpoint to be hit by other running extensions or the next extension to be activated within the shared instance pool. -
After you finish debugging the extension, be sure to remove the
System.
method before you deploy the extension to your production environment.Diagnostics. Debugger. Launch()