CRM 2011: Error in a simple plugin

Respondido CRM 2011: Error in a simple plugin

  • Saturday, April 14, 2012 11:50 PM
     
      Has Code

    Hi all, here is an error with a very simple plugin developed with crm developer toolkit:

    Source code:

    namespace InternalCaseNumber.InternalCaseNumberPlugin
    {
        using System;
        using System.ServiceModel;
        using Microsoft.Xrm.Sdk;
        using Microsoft.Xrm.Sdk.Query;
        //using Microsoft.Crm.Sdk.Messages;
        using System.Runtime.Serialization;
        /// <summary>
        /// PostInternalCaseCreate Plugin.
        /// </summary>    
        public class PostInternalCaseCreate: Plugin
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="PostInternalCaseCreate"/> class.
            /// </summary>
            public PostInternalCaseCreate()
                : base(typeof(PostInternalCaseCreate))
            {
                base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "intercom_internalrequest", new Action<LocalPluginContext>(ExecutePostInternalCaseCreate)));
    
                // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
                // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
            }
    
            /// <summary>
            /// Executes the plug-in.
            /// </summary>
            /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
            /// <see cref="IPluginExecutionContext"/>,
            /// <see cref="IOrganizationService"/>
            /// and <see cref="ITracingService"/>
            /// </param>
            /// <remarks>
            /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
            /// The plug-in's Execute method should be written to be stateless as the constructor
            /// is not called for every invocation of the plug-in. Also, multiple system threads
            /// could execute the plug-in at the same time. All per invocation state information
            /// is stored in the context. This means that you should not use global variables in plug-ins.
            /// </remarks>
            protected void ExecutePostInternalCaseCreate(LocalPluginContext localContext)
            {
                if (localContext == null)
                {
                    throw new ArgumentNullException("localContext");
                }
    
                // TODO: Implement your custom Plug-in business logic.
    
                IPluginExecutionContext context = localContext.PluginExecutionContext;
                IOrganizationService service = localContext.OrganizationService;
                //ITracingService tracingService = localContext.TracingService;
    
    
    
    
    
    
                // The InputParameters collection contains all the data passed in the message request.
                if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
                {
                    // Obtain the target entity from the input parmameters.
                    Entity entity = (Entity)context.InputParameters["Target"];
    
                    try
                    {
                        //check if the account number exist
    
                        if (entity.Attributes.Contains("new_subject") == true)
                        {
    
    EntityReference subject = (EntityReference)entity.Attributes["new_subject"];
                            string subjectId = subject.Id.ToString();
                            throw new InvalidPluginExecutionException(subjectId);
    }
                    }
    
                    catch (FaultException ex)
                    {
                        throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                    }
    
                }
    }
        }
    }

    Error:

    Error registering plugins and/or workflows. Supported deployment does not agree with message availability

    Please advise..

All Replies