public void Execute(IServiceProvider serviceProvider) { //Extract the tracing service for use in debugging sandboxed plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); var service = serviceFactory.CreateOrganizationService(context.UserId); OrganizationServiceContext ctx = new OrganizationServiceContext(service); FaultException ex1 = new FaultException(); //throw new InvalidPluginExecutionException("asdfsd", ex1); // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { // Obtain the target entity from the input parameters. EntityReference entityRef = (EntityReference)context.InputParameters["Target"]; Entity preEntity = (Entity)context.PreEntityImages["names"]; var entityName = preEntity.GetAttributeValue <string>("fp_name"); if (entityRef.LogicalName != "fp_fieldnamepopulator") { return; } try { var populator = new Populator(service, entityName); if (!populator.destroyPluginSteps()) { throw new InvalidPluginExecutionException("Something went wrong", ex1); } } catch (FaultException <OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the Field Name Populator plug-in.", ex); } catch (Exception ex) { tracingService.Trace("Field Name Populator Plugin: {0}", ex.ToString()); throw; } } }