I have s very simple plugin registered on pre operation stage at update message having execution mode as Sysnchronous. Ia m getting exception as An error occurred in the plguin.
Can anyone help me here to know where I am going wrong.
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory _serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService _orgService = _serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "account")
{
string notes = "test";
try
{
if (entity.Attributes.Contains("numberofemployees"))
{
entity.attributes["description"] = notes;
}
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occured in plugin:",ex);
}
}
}