Debug Plugin in Dynamics CRM 2011

In earlier versions of CRM, in order to debug any Plug-in or Custom workflow activity it was mandatory to copy the DLL and PDB files to “%Microsoft Dynamics CRM%\server\bin\assembly” directory and then attach the source code to server’s worker process i.e. w3wp.exe

Dynamics CRM 2011 provides a better mechanism by which developers can achieve the above with just few clicks and without accessing the CRM server.

Here’s how

Procedure

  1. Build and register your Plugin as usual.

    Register Plugin

  2. Inside Plugin Registration Tool, you’ll find a button which says Install Profiler, Click it.

    Install Profiler

  3. Once it is done, you will find an entry for Plug-in Profiler beneath your assemblies.
  4. Now, go-to the step for which you want to debug your plugin and press the Profile button.

    Start Profiling

  5. Once done, you will see a tag (Profiled) adjacent to the step.

    Profiled

  6. Now go ahead and execute the plugin i.e. perform the steps in CRM that will trigger this plugin.
  7. If the code has any errors, then CRM will provide you a log file to download; go ahead and download the file. (see screenshot below)

    Error Log

  8. Now, inside Visual Studio, insert Breakpoints wherever you feel and use Attach to Process button and attach the code to Plugin Registration Tool exe.
    Note: Initially you will see that VS cannot find symbols so breakpoints will not be hit.

    Attach to Process

  9. Now, go back to Plugin Registration Tool and Select the Step which you profiled earlier hit Debug button.

    Debug

  10. A new Dialog-box will be presented to you, refer to the necessary files and hit Start Plug-in Execution button.

    Start Plug-in Execution

  11. Wait for a few seconds and you will start to see the following in Plug-in Traces window from Debug screen.

    Plug-in Trace

  12. Now, switch to Visual Studio and you will see that your first Breakpoint has been hit.

    Breakpoint

15 Comments Debug Plugin in Dynamics CRM 2011

    1. Piyush

      Hi Bruno, sorry for such a delayed response. For custom workflow am afraid to say that you’ll have to go with the conventional way of keeping the DLL + PDB on the Server’s assembly folder and attach the debugger with CRM Async Process and then perform the step which will execute the workflow. HTH

  1. Nordine

    hi,
    the pluginregistration throw an exception when i try to set profile location .
    the exception is :

    Unhandled Exception: System.ArgumentException: Unable to parse the OrganizationServiceFault.
    Nom du paramètre : serializedReport
    à PluginProfiler.Library.ProfilerUtility.ExtractReport(String serializedReport)
    à PluginProfiler.Library.ProfilerUtility.DeserializeProfilerReport(String assemblyFilePath, String logFilePath)
    à PluginProfiler.Library.ProfilerExecutionUtility.RetrieveReport(String logFilePath)
    à Microsoft.Crm.Tools.PluginRegistration.OrganizationHelper.ParseReportOrShowError(IWin32Window owner, FileBrowserControl profilePathControl, Boolean requireReportParse, ProfilerPluginReport& report)
    Inner Exception: System.InvalidOperationException: Message does not contain a serialized value.
    à PluginProfiler.Library.ProfilerUtility.ExtractReportFromFault(OrganizationServiceFault fault)
    à PluginProfiler.Library.ProfilerUtility.ExtractReport(String serializedReport).
    if anay one get idea, please post it
    thanks

    1. Piyush

      Looking at the error which it throws for you, it just seems that the debug profile which you are using is wrong. Plugin Registration tool is having some problems parsing your ErrorDetails file.

          1. Naveen

            Piyush.. i am also facing same problem. i am not able to debug my plugin. may be Profile location( Error Details) is not correct. how can i solve this?

          2. Naveen

            Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): PluginProfiler.Plugins.ProfilerPlugin: System.TypeInitializationException: The type initializer for ‘PluginProfiler.Plugins.ServiceWrappers.ServiceProviderWrapper’ threw an exception.Detail:

            -2147220956

            Unexpected exception from plug-in (Execute): PluginProfiler.Plugins.ProfilerPlugin: System.TypeInitializationException: The type initializer for ‘PluginProfiler.Plugins.ServiceWrappers.ServiceProviderWrapper’ threw an exception.
            2014-01-30T09:55:02.6599651Z

            [PluginProfiler.Plugins: PluginProfiler.Plugins.ProfilerPlugin]
            [3fab5f5b-9489-e311-ac09-6c3be5a83230: Employee.Plug_ins.JobTitleProviderPlugin: Create of contact (Profiler)]

          3. Piyush

            Naveen, there seems to be a problem with your profiler. Can you try uninstalling the current profiler, get the latest SDK and then re-install it.

  2. Anwesha

    I also get a similar error while trying to mention the path of the Errortxt log when I try to enter the detaills in the Debug Dialog

    Unhandled Exception: System.ArgumentException: Unable to parse the OrganizationServiceFault.
    Parameter name: serializedReport
    at PluginProfiler.Library.ProfilerUtility.ExtractReport(String serializedReport)
    at PluginProfiler.Library.ProfilerUtility.DeserializeProfilerReport(String assemblyFilePath, String logFilePath)
    at PluginProfiler.Library.ProfilerExecutionUtility.RetrieveReport(String logFilePath)
    at Microsoft.Crm.Tools.PluginRegistration.OrganizationHelper.ParseReportOrShowError(IWin32Window owner, FileBrowserControl profilePathControl, Boolean requireReportParse, ProfilerPluginReport& report)
    Inner Exception: System.InvalidOperationException: Message does not contain a serialized value.
    at PluginProfiler.Library.ProfilerUtility.ExtractReportFromFault(OrganizationServiceFault fault)
    at PluginProfiler.Library.ProfilerUtility.ExtractReport(String serializedReport)

    1. Piyush

      Can you share your ErrorDetails.txt file here so that I can review. Am sure this is because of some required text missing in the file.
      Just upload it to dropbox or something and share the path here.

  3. Liton

    Hi, I can use the plugin profile to debug any custom workflow activity but it throws error messages when I want to debug a plugin. I’ve received the following error messages. Any help!

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): PluginProfiler.Plugins.ProfilerPlugin: System.TypeInitializationException: The type initializer for ‘PluginProfiler.Plugins.ServiceWrappers.ServiceProviderWrapper’ threw an exception.Detail:

    -2147220956

    Unexpected exception from plug-in (Execute): PluginProfiler.Plugins.ProfilerPlugin: System.TypeInitializationException: The type initializer for ‘PluginProfiler.Plugins.ServiceWrappers.ServiceProviderWrapper’ threw an exception.
    2013-10-22T19:58:46.965839Z

    [PluginProfiler.Plugins: PluginProfiler.Plugins.ProfilerPlugin]
    [a69e0c4e-543b-e311-8b3b-0017a477fc08: OWB.CRM.Plugin.Close_CBS_Case_Resolution: Update of incident (Profiler)]

    1. Piyush

      How is your Plugin registered, Sandbox? Here is what I’m gonna do;

      • Update the Plugin Assembly using Registration Tool
      • Re-Install the Plugin-Profiler
      • Generate a new Profile i.e. ErrorDetails.txt file and then use it to debug the plugin

      If the above fixes your problem it’s great, else you can also try IISReset and restarting Async service and the Sandbox service.
      In any case, do let me know and we can discuss further and try resolving your issue.
      Thanks for dropping by.