I am trying to to implement a plugin that parses the email body from html email to text.
The problem is that for some reason
pluginExecutionContext.InputParameters.Contains(
"Target") is false and the following error is thrown
01/28/2013 16:32:57 : #9628 - An error occurred while delivering the e-mail message with subject "email test " in mailbox xxx for delivery to yyy System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]:
--------------->ERROR 2a (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
The general configuration of the plugin is:
Message: DeliverIncoming
Primary entity: email
Secondary entity: none
Stage: pre-operation
Mode : synchronous
And the code is:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; namespace HtmlEmailToText2 { public class ConvertPlugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { //Extract the tracing service ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); if (tracingService == null) { throw new InvalidPluginExecutionException("Failed to retrieve the tracing service."); } IPluginExecutionContext pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (pluginExecutionContext == null) { throw new InvalidPluginExecutionException("Failed to retrieve the execution context."); } Entity entity = null; // additional checks: // plug-in is not running synchronously // plug-in is not running against the 'Email' entity // plug-in is not running in the 'pre-processing' stage of the pipeline // e-mail handled by the e-mail router triggers the "DeliverIncoming" event if (pluginExecutionContext.PrimaryEntityName != "email") { throw new InvalidPluginExecutionException("-------------->ERROR 1"); } if (pluginExecutionContext.InputParameters.Contains("Target") ) { if (pluginExecutionContext.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parmameters. entity = (Entity)pluginExecutionContext.InputParameters["Target"]; } else { throw new InvalidPluginExecutionException("--------------->ERROR 2b"); } } else { throw new InvalidPluginExecutionException("--------------->ERROR 2a" + pluginExecutionContext.InputParameters.Contains("Target").ToString()); } try { tracingService.Trace("The plugin has started.."); // entity["new_textdescription"] = ConvertHtmlToText((string)entity["description"]); entity.Attributes["new_textdescription"] = "testing "; // pluginExecutionContext.InputParameters["Target"] = entity; // IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); // IOrganizationService service = factory.CreateOrganizationService(pluginExecutionContext.UserId); // service.Create(entity); tracingService.Trace("The plugin has ended.."); throw new InvalidPluginExecutionException("This is from a plugin that i have created "); } catch (Exception ex) { throw new InvalidPluginExecutionException("---------------->ERROR : ", ex); } } } }
Could anybody out there explain me what i am doing wrong please.