Debugging online plugin in CRM 2011

Hi,

Let us take a simple plugin to understand the debugging process. We are throwing the exception to get the profile which we will use for debugging.


public
class
Class1 : IPlugin

{


public
void Execute(IServiceProvider serviceProvider)

{


IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

 


Entity entity;


// Check if the input parameters property bag contains a target


// of the create operation and that target is of type Entity.


if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is
Entity)

{


// Obtain the target business entity from the input parameters.

entity = (Entity)context.InputParameters[“Target”];

 


// Verify that the entity represents a contact.


if (entity.LogicalName != “contact”) {

 


throw
new
InvalidPluginExecutionException();


return;

}

}

 

}

}

We need to use the latest plugin registration tool that will have the option of Installing Profiler which we will use. Get it from the latest SDK of CRM 2011.

Register the plugin (debug version) and corresponding step using plugin registration tool.

Select Install Profiler in Plugin Registration tool and wait till the installation is complete.


Select the Step in Plugin and Click Profile in the tool

Select Ok in the dialog box

Open CRM and perform the step that will run the plugin and throw the exception.

Download the log file.

Open Visual Studio and attach debugger to PluginRegistrationTool.exe

Go back to Plugin Registration tool, select the step and select Debug from the tool bar.

 

Specfiy the log file in the Profile location and plugin assembly that is in debug folder.

Click on Start Execution to start debugging

Happy debugging J

Leave a comment