locked
Help Needed with plugin error RRS feed

  • Question

  • CRM2013 & VS2012

    I have tried creating a plugin following an example. I have registered the plugin and step using the CRM2013SDK plugin tool. When the plugin is run in CRM I get the following error

    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 (Constructor): FMAutoReports.Plugins.Plugin: System.MissingMethodException: Constructor on type 'FMAutoReports.Plugins.Plugin' not found.Detail: 
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147220956</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Unexpected exception from plug-in (Constructor): FMAutoReports.Plugins.Plugin: System.MissingMethodException: Constructor on type 'FMAutoReports.Plugins.Plugin' not found.</Message>
      <Timestamp>2014-10-09T10:43:30.1048159Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>
    
    [FMAutoReports.Plugins: FMAutoReports.Plugins.Plugin]
    [d09d4132-0e4f-e411-80dd-00155d01d308: FMAutoReports.Plugins.Plugin: Create of new_test]
    
    
    </TraceText>
    </OrganizationServiceFault>

    my code - please bare in mind this is new to me

    using System;
    using System.Activities;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Crm.Sdk.Messages;
    using FMAutoReports.Plugins.ReportService;
    using Microsoft.Crm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    
    namespace FMAutoReports
    {
        public class SendReport : CodeActivity
        {
            protected override void Execute(CodeActivityContext executionContext)
            {
                try
                {
                    IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
                    IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
     
                    Guid accountId = context.PrimaryEntityId;
                    byte[] result = null;
     
                    FMAutoReports.Plugins.ReportService.ReportExecutionService rs = new ReportExecutionService();
     
                    // Credential to connect with CRM
                    rs.Credentials = new System.Net.NetworkCredential(xxxx, xxxx, xxxx);
     
                    // Setting the URL of the Reporting Server
                    rs.Url = "http://TESTSERVER/ReportServer/ReportExecution2005.asmx";
     
                    string reportPath = "/TEST_MSCRM/TEST Reconocile";
                    // Specify the report path from the reporting server
                    // Note: To get the report name, report must be published for the external use.
                    // To do this edit the report from CRM and publish it for external use.
                    // After publishing it for external use report name will be visible in the reporting server instead of the report id.
     
                    string format = "PDF";
                    string historyID = null;
                    string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
                    string encoding;
                    string mimeType;
                    string extension;
                    Warning[] warnings = null;
                    string[] streamIDs = null;
     
                    ExecutionInfo execInfo = new ExecutionInfo();
                    ExecutionHeader execHeader = new ExecutionHeader();
                    rs.ExecutionHeaderValue = execHeader;
                    execInfo = rs.LoadReport(reportPath, historyID);
     
                    String SessionId = rs.ExecutionHeaderValue.ExecutionID;
     
                    result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
     
                    //Create email activity
                    Entity email = new Entity();
                    email.LogicalName = "email";
                    email.Attributes.Add("regardingobjectid", new EntityReference("account", accountId));
     
                    //Creating EntityReference for from, to and cc. Need to be changed according to your requirement
    //                EntityReference from = new EntityReference("systemuser", senderUserId);
    //                EntityReference to = new EntityReference("contact", recieverUserId);
    //                EntityReference cc = new EntityReference("contact", recieverCCUserId);
     
                    //Creating party list
    //                Entity fromParty = new Entity("activityparty");
    //                fromParty.Attributes.Add("partyid", from);
     //               Entity toParty = new Entity("activityparty");
    //                toParty.Attributes.Add("partyid", to);
     //               Entity ccParty = new Entity("activityparty");
     //               ccParty.Attributes.Add("partyid", cc);
     
     //               EntityCollection collFromParty = new EntityCollection();
     //               collFromParty.EntityName = "systemuser";
     //               collFromParty.Entities.Add(fromParty);
     
     //               EntityCollection collToParty = new EntityCollection();
     //               collToParty.EntityName = "contact";
     //               collToParty.Entities.Add(toParty);
     
    //                EntityCollection collccParty = new EntityCollection();
    //                collccParty.EntityName = "contact";
    //                collccParty.Entities.Add(ccParty);
     
                    // Adding from, to and cc to the email
                    email.Attributes.Add("from", "me@me.co.uk");
                    email.Attributes.Add("to", "you@me.co.uk");
                    email.Attributes.Add("cc", "him@me.co.uk");
     
                    email.Attributes.Add("subject", "TEST SENDING PDF FROM CRM ");
                    email.Attributes.Add("description", "This is a test to email a report direct from crm when a record is created");
                    Guid emailID = service.Create(email); // Create the email
     
                    // Attaching Pdf Report
                    int NextActorID = new int();
                    RetrieveEntityRequest request = new RetrieveEntityRequest();
                    request.LogicalName = "email";
                    RetrieveEntityResponse response = (RetrieveEntityResponse)service.Execute(request);
                    int objecttypecode = response.EntityMetadata.ObjectTypeCode.Value;
     
                    Entity attachment = new Entity("activitymimeattachment");
                    attachment.Attributes.Add("subject", "Report");
                    attachment.Attributes.Add("filename", "Test Report.pdf");
                    attachment.Attributes.Add("body", Convert.ToBase64String(result));
                    attachment.Attributes.Add("filesize", Convert.ToInt32(result.Length.ToString()));
                    attachment.Attributes.Add("mimetype", "text/plain");
                    attachment.Attributes.Add("attachmentnumber", NextActorID);
                    attachment.Attributes.Add("objectid", new EntityReference("email", new Guid(email.Id.ToString())));
                    attachment.Attributes.Add("objecttypecode", objecttypecode);
                    service.Create(attachment); //Create the attachment
     
                    // Sending email
                    SendEmailRequest reqSendEmail = new SendEmailRequest();
                    reqSendEmail.EmailId = emailID;
                    reqSendEmail.TrackingToken = "";
                    reqSendEmail.IssueSend = true;
                    SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);
                }
                catch (Exception err)
                {
                    // Throw error message
                }
            }
        }
    }
    


    Dont ask me .. i dont know

    Thursday, October 9, 2014 11:03 AM

Answers

  • your code is a custom worfklow activity (:CodeActivity) not a plugin.

    a plugin definition is 

    using System;
    using System.ServiceModel;
    
    // Microsoft Dynamics CRM namespace(s)
    using Microsoft.Xrm.Sdk;
    
    namespace Microsoft.Crm.Sdk.Samples
    {
     	public class FollowupPlugin: IPlugin
    	{
    		/// <summary>
            /// A plug-in that creates a follow-up task activity when a new account is created.
    		/// </summary>
            /// <remarks>Register this plug-in on the Create message, account entity,
            /// and asynchronous mode.
            /// </remarks>
            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));


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, October 9, 2014 11:08 AM

All replies

  • your code is a custom worfklow activity (:CodeActivity) not a plugin.

    a plugin definition is 

    using System;
    using System.ServiceModel;
    
    // Microsoft Dynamics CRM namespace(s)
    using Microsoft.Xrm.Sdk;
    
    namespace Microsoft.Crm.Sdk.Samples
    {
     	public class FollowupPlugin: IPlugin
    	{
    		/// <summary>
            /// A plug-in that creates a follow-up task activity when a new account is created.
    		/// </summary>
            /// <remarks>Register this plug-in on the Create message, account entity,
            /// and asynchronous mode.
            /// </remarks>
            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));


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, October 9, 2014 11:08 AM
  • Thank you, I see the error of my ways and have followed this tutorial http://mubashersharif.blogspot.co.uk/2013/01/custom-workflowactivity-understanding-development.html

    however, when running the workflow I get the following error. I am struggling to understand what the issue is

    Plugin Trace:
    
    [FMAutoReports.Workflow: FMAutoReports.Workflow.SendReports]
    [BACS Reports: ARUDD Listing]
    Entered SendReports.Execute(), Activity Instance Id: 1, Workflow Instance Id: dd3dbe99-56fc-46df-91b7-ed764ca15e58
    SendReports.Execute(), Correlation Id: 3027e662-ac26-4c64-adbf-01c0d0609da4, Initiating User: 68413345-e5b9-e311-80b8-00155d04fa2d
    Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Account With Id = 68b05713-0c4f-e411-80dd-00155d01d308 Does Not Exist (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
    
    
    Error Message:
    
    Unhandled Exception: Microsoft.Crm.CrmException: Account With Id = 68b05713-0c4f-e411-80dd-00155d01d308 Does Not Exist
       at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
       at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
    


    Dont ask me .. i dont know

    Thursday, October 9, 2014 2:33 PM