How to enable debugging of the initialization phase of an extension
If you wish to debug the initialization phase of an extension follow these steps to ensure enough time is available to attach a debugger to the extension process. See the following section for an alternative to this approach which relies on adding debug specific code into your extension.
- Log into ArcGIS Server Manager.
- Ensure that the extension you wish to debug into is deployed to ArcGIS Server.
- Publish a map or image service and enable the extension you wish to debug.
- Navigate to Site > Extensions. Click the Debug Settings button.
- Click Enable debugging of extensions to enable debugging.
- Check the Suspend service startup checkbox and provide a time window in milliseconds if you wish to debug into the lifecycle methods of your extension. Examples of lifecycle methods are init() and shutdown(). These methods are invoked by the parent map service during the startup and shutdown phases. When the map service starts, Server freezes initialization of the map service for the duration specified by this time window, thus allowing you to set a breaking point in init() or other lifecycle methods and connect the IDE debug session to the ArcGIS Server process hosting the extension.
- Ignore the options for specifying a port range. This only applies to extensions built with Java.
- Click Save. Debugging is now enabled on ArcGIS Server.
- Restart the map service that your extension is enabled on, for above changes to take effect.
How to debug into .NET extensions using Visual Studio
When debugging the initialization phase you can follow the above steps to ensure you have enough time to attach the Visual Studio debugger before the extension startup logic begins executing. To attach the Visual Studio debugger use the Debug > Attach to process option in Visual Studio.
An alternative to this approach is to add an explicit call to the System.Diagnostics.Debugger.Launch() method in your extension code. This method launches the debugger when the code is triggered. When you use this approach, you can debug any part of an extension, including life cycle methods like IObjectConstruct.Construct() or other initialization methods.
- Place the following line of code as the first line of your SOE's Init() function:
System.Diagnostics.Debugger.Launch();
- Place a breakpoint in your extension code where you want to start debugging.
- Build the project in Debug mode. Keep the project open when performing the remainder of these steps.
- Deploy the updated .soe file in Manager and restart the service.
- Accept all prompts asking if you want to debug, and if you want to attach the debugger to a process.
- If necessary, access a property or method on your extension that would hit the breakpoint.
- Use the Visual Studio debugger to step through the code as you normally would.
Be sure to remove the Launch() method from your code before you deploy the extension to a staging or production server.
How to disable debugging
If you have enabled debugging in order to add time for suspending service startup, be sure to disable this option again to avoid having your service continue to pause during startup.
- Log into ArcGIS Server Manager.
- Navigate to Site > Extensions. Click the Debug Settings button.
- Uncheck the Enable debugging of extensions check-box to disable debugging.
- Click Save. Debugging is now disabled on ArcGIS Server.
Tips
- Before turning debugging on, open the "Logs" page in Manager and verify that the log level in "Settings" section is set to Verbose. Setting log level to Verbose will ensure that logs will be generated at this level.
- Remember to turn debugging off in the Site -> Extensions -> Debug Settings dialog in Manager, after your debugging session is over.
- The extension you debug into must be deployed to a Server that is installed locally on the machine you are debugging the extension on.