none
Plugin - Constructor Not Found

    Question

  • I am getting the following error when running a plugin on CRM Online.  This error shows in the System job for the plugin.

    Unexpected exception from plug-in (Constructor): MYC.Plugin: System.MissingMethodException: Constructor on type 'MYC.Plugin' not found.

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Constructor): MYC.Plugin: System.MissingMethodException: Constructor on type 'MYC.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): MYC.Plugin: System.MissingMethodException: Constructor on type 'MYC.Plugin' not found.</Message>
      <Timestamp>2013-05-15T20:26:11.6240733Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>
    
    [MYC: MYC.Plugin]
    [6be6af93-82bd-e211-951f-78e7d162bad9: MYC.Plugin: Update of salesorder]
    
    
    </TraceText>
    </OrganizationServiceFault>
    

    Here is my C# code file - this is the only file in the project. I compiled it with VS 2012 Pro (target framework .NET 4.0)

    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    
    namespace MYC.Plugin
    {
        public class OrderStatus : IPlugin
        {
            private Guid _cid = context.primaryentityid;
            //public OrderStatus();
    
            public void Execute(IServiceProvider serviceProvider)
            {
                // Obtain the execution context from the service provider.
                IPluginExecutionContext context =
                    (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                // Get a reference to the organization service.
                IOrganizationServiceFactory factory =
                    (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
    
                // Get a reference to the tracing service.
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    
                try
                {
                    UpdateOrder(service, _cid, 220570000);
                }
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    // Handle the exception.
           
                }
            }
    
    
            private void UpdateOrder(IOrganizationService service, Guid _cid, int newstatus)
            {
                try
                {
                    Entity _con = new Entity("Order");
                    _con.Id = _cid;
                    _con["statuscode"] = newstatus;
    
                    service.Update(_con);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
    
                }
    
            }
        }
    
    
    }
    

    Do I have to add a line for the constructor?  What do I put - and where?  

    Thanks!

    Wednesday, May 15, 2013 8:42 PM

Answers

  • Yes, you have to write the constructor and add the following line to your code before execute method.

    public OrderStatus(string config, string secureConfig)
    {           
    }
    public void Execute(IPluginExecutionContext context)
    {

    // Your code

    }

                

    • Marked as answer by Richard Magee Thursday, May 16, 2013 8:58 PM
    Thursday, May 16, 2013 5:29 AM

All replies

  • Yes, you have to write the constructor and add the following line to your code before execute method.

    public OrderStatus(string config, string secureConfig)
    {           
    }
    public void Execute(IPluginExecutionContext context)
    {

    // Your code

    }

                

    • Marked as answer by Richard Magee Thursday, May 16, 2013 8:58 PM
    Thursday, May 16, 2013 5:29 AM
  • Hello,

    I don't see any reason why you should use constructor here, but you are trying to access context before it's declaration so change your code like below and try

     private Guid _cid = Guid.Empty;

    and then in your plugin

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

    _cid = context.primaryentityid;


    HTH


    My Website | My Blog | Follow me on Twitter | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Thursday, May 16, 2013 5:44 AM
    Moderator
  • Hi Richard,

    I figured out another issue in your code.

    Entity _con = new Entity("Order");
    _con.Id = _cid;
    _con["statuscode"] = newstatus;
    
     service.Update(_con);


    I guess you are trying to update order entity.The logical name of order entity is "salesorder" not "Order".

    Change the line,

    Entity _con = new Entity("Order");

     to 

    Entity _con = new Entity("salesorder");


    Thank you, DT

    Thursday, May 16, 2013 7:41 AM
  • Hi,

    You can use developer toolkit to create plugin, workflow and Script. Then no such constructor problem will arise. It is a toolkit provided by Microsoft to ease our development.

    http://iknowcrm.blogspot.in/2013/05/microsoft-hasdeveloped-developer.html

    Thursday, May 16, 2013 8:21 AM
  • Thank you everyone!   All of your posts were very helpful.  I used the developer toolkit and pasted my code there - but I still got the same Constructor Not Found Error.

    When I added the code that Hardik gave above, it worked.  Thanks!

    Thursday, May 16, 2013 9:00 PM