Troubleshooting plug-ins

During plug-in development, we need to troubleshoot our plug-in code for different errors that we may face during execution of the code. It is always a good practice to have your code well documented with proper exception handling. We can troubleshoot plug-in code in three ways:

  1. Using the ITracingService service.
  2. Using debugging.
  3. Writing logs to text files.

ITracingService helps us to generate logging information that we may want to do at different steps. This is especially useful when we don't have debugging tools available and need logging information to troubleshoot our code. We can get ITracingService from the service provider object as follows:

//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

ITracingService has one method Trace that we can use to create logs as follows:

//adding log information
tracingService.Trace("Logging Message");

All the tracing information generated in plug-ins can be accessed in the following ways:

  • Using the Download Log File button in the Business Process Error dialog
  • Using the Plug-in Trace log available under Settings | Plug-In Trace Log
  • Using log files generated in the CRM installation path: Microsoft Dynamics CRMTrace

Plug-in tracing in CRM applications is not enabled by default; we need to enable it from the Customization tab by navigating to Settings | System Settings. Once this setting is enabled we can see tracing information in the CRM as follows:

Troubleshooting plug-ins

We can also get tracing information into log files at the server level if tracing is enabled in the CRM server. To enable tracing in the CRM server you can refer to: https://technet.microsoft.com/en-us/library/hh699694.aspx#BKMKserver_level_tracing.

Debugging plug-ins

Debugging is the process where we execute our code line by line in order to identify runtime errors and fix them. We can debug both non-isolation and isolation plug-ins; in the case of non-isolation plug-ins, we need to copy the PDB and DLL files to the serverinassembly folder on the CRM server and we need to attach the service process based on the plug-in type in Visual Studio. The following table presents the different services that we need to attach:

Plug-in Type

Process Name

Online

w3wp

Offline

microsoft.crm.application.hoster

Asynchronous plug-in and workflow

Crmasyncservice

You need to perform the following steps to debug your on-premise plug-in, where Visual Studio is installed on the CRM server:

  1. Build your code and keep the PDB and DLL files in serverinassembly.
  2. Register the updated code to the CRM.
  3. Attach the w3wp process in Visual Studio (make sure you are logged in with admin rights).
  4. Add a breakpoint in your source code.
  5. Execute your event in the CRM.

Note

If Visual Studio is not installed on the CRM server then we need to use remote debugging. You can refer to https://community.dynamics.com/crm/b/zhongchenzhoustipstricksandportaldevelopment/archive/2012/05/16/dynamics-crm-remote-debugging-step-by-step for the steps required for remote debugging.

In the case of sandbox plug-ins, we need to copy the PDB and DLL files under serverinassembly folder on the server running the sandbox worker process (the Sandbox Processing Service role server). In the case of the sandbox server, we need to attach Microsoft.Crm.Sandbox.WorkerProcess for debugging.

Note

We can also debug our plug-in using the plug-in registration tool; this is especially useful when you are working with CRM Online deployment. Please refer to: http://nishantrana.me/2014/07/02/debugging-online-plugin-in-crm-2013/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.136.144