This document is archived and information here might be outdated.  Recommended version.


Walkthrough: Debugging an extension (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Extending ArcGIS Server > Walkthrough: Debugging an extension (ArcObjects .NET 10.6 SDK)

Debugging an extension


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.
  1. Log into ArcGIS Server Manager.
  2. Ensure that the extension you wish to debug into is deployed to ArcGIS Server.
  3. Publish a map or image service and enable the extension you wish to debug.
  4. Navigate to Site > Extensions. Click the Debug Settings button.
  5. Click Enable debugging of extensions to enable debugging.
  6. 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.
  7. Ignore the options for specifying a port range. This only applies to extensions built with Java.
  8. Click Save. Debugging is now enabled on ArcGIS Server.
  9. 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.
  1. Place the following line of code as the first line of your SOE's Init() function:
[C#]
System.Diagnostics.Debugger.Launch();
  1. Place a breakpoint in your extension code where you want to start debugging.
  2. Build the project in Debug mode. Keep the project open when performing the remainder of these steps.
  3. Deploy the updated  .soe file in Manager and restart the service.
  4. Accept all prompts asking if you want to debug, and if you want to attach the debugger to a process.
  5. If necessary, access a property or method on your extension that would hit the breakpoint.
  6. 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.
  1. Log into ArcGIS Server Manager.
  2. Navigate to Site > Extensions. Click the Debug Settings button.
  3. Uncheck the Enable debugging of extensions check-box to disable debugging.
  4. 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.