locked
Updated custom workflow activity causing error when registering dll RRS feed

  • Question

  • I updated the code for a custom workflow from CRM 4 to CRM 2011. I'm not sure if I've done it correctly, as when I try to update the workflow assembly via the plugin registration tool, I'm getting the following error:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Plug-in assembly does not contain the required types or assembly content cannot be updated.
    Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <ErrorCode>-2147204725</ErrorCode>
      <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Plug-in assembly does not contain the required types or assembly content cannot be updated.</Message>
      <Timestamp>2014-02-27T11:05:52.2671376Z</Timestamp>
      <InnerFault>
        <ErrorCode>-2147204725</ErrorCode>
        <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
        <Message>Plug-in assembly does not contain the required types or assembly content cannot be updated.</Message>
        <Timestamp>2014-02-27T11:05:52.2671376Z</Timestamp>
        <InnerFault i:nil="true" />
        <TraceText i:nil="true" />
      </InnerFault>
      <TraceText i:nil="true" />
    </OrganizationServiceFault>
    
    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity)
       at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.UpdateCore(Entity entity)
       at PluginRegistrationTool.RegistrationHelper.UpdateAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly, PluginType[] type) in C:\Users\scunningham\Desktop\2011sdk\sdk\tools\pluginregistration\RegistrationHelper.cs:line 263
       at PluginRegistrationTool.PluginRegistrationForm.btnRegister_Click(Object sender, EventArgs e) in C:\Users\sjones\Desktop\2011sdk\sdk\tools\pluginregistration\PluginRegistrationForm.cs:line 382

    This is the original C# code:

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Workflow;
    using Microsoft.Crm.Sdk.Query; 
    
    namespace GetReceipientEmail
    {
        [CrmWorkflowActivity("Find Customer with specified email address")]
    
        public class MatchSenderWithExistingCustomerActivity : System.Workflow.Activities.SequenceActivity
        {
            protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
                {
                      IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
                      IWorkflowContext context = contextService.Context;
                      ICrmService crmService = context.CreateCrmService(); 
                      Guid accountId = MatchSenderWithExistingAccount(crmService, this.sender);
                      this.accountId = new Lookup("contact", accountId);
                      return ActivityExecutionStatus.Closed;
                }
             private Guid MatchSenderWithExistingAccount(ICrmService crmService, string fromAddress)
            {
                QueryByAttribute query = new QueryByAttribute();
                query.EntityName = EntityName.contact.ToString();
                query.Attributes = new string[] { "emailaddress1" };
                query.Values = new string[] { fromAddress };
                RetrieveMultipleRequest retrieveMultipleRequest = new RetrieveMultipleRequest();
                retrieveMultipleRequest.Query = query;
                retrieveMultipleRequest.ReturnDynamicEntities = true;
                RetrieveMultipleResponse retrieveMultipleResponse = (RetrieveMultipleResponse)crmService.Execute(retrieveMultipleRequest);
                Guid contactId = Guid.Empty;
                foreach (BusinessEntity busEntity in retrieveMultipleResponse.BusinessEntityCollection.BusinessEntities)
                {
                    contactId = ((Key)(((DynamicEntity)busEntity)["contactid"])).Value;
                    break;
                }
                  
                return contactId;
            }
    
            public static DependencyProperty senderProperty = DependencyProperty.Register("sender", typeof(string), typeof(MatchSenderWithExistingCustomerActivity));
            [CrmInput("Sender")]
            public string sender
            {
                get
                {
                    return (string)base.GetValue(senderProperty);
                }
    
                set
                {
                    base.SetValue(senderProperty, value);
                }
            }
            public static DependencyProperty accountIdProperty = DependencyProperty.Register("accountId", typeof(Lookup), typeof(MatchSenderWithExistingCustomerActivity));
            [CrmOutput("AccountId")]
            [CrmReferenceTarget("contact")]
    
            public Lookup accountId
            {
                get
                {
                    return (Lookup)base.GetValue(accountIdProperty);
                }
                set
                {
                    base.SetValue(accountIdProperty, value);
                }
            }
                }
    	
    }
    

    And here's my updated version. I used a guide to help me update the original to this:

    using System;
    using System.ServiceModel;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Activities;
    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Client;
    
    namespace GetReceipientEmail
    {
        public class MatchSenderWithExistingCustomerActivity : CodeActivity
        {
            protected override void Execute(CodeActivityContext executionContext)
                {
                      IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();    
                      IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();                  
                      IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    
                      Guid accountId = MatchSenderWithExistingAccount(service, SenderId.Get<EntityReference>(executionContext).Id.ToString());                 
                      this.SenderId = new EntityReference("contact", accountId);
    
                }
    
            private Guid MatchSenderWithExistingAccount(IOrganizationService crmService, string fromAddress)
            {           
                QueryByAttribute query = new QueryByAttribute("contact");
                query.Attributes.Add("emailaddress1");
                query.Values.Add(fromAddress);
                RetrieveMultipleRequest retrieveMultipleRequest = new RetrieveMultipleRequest();
                retrieveMultipleRequest.Query = query;
                RetrieveMultipleResponse retrieveMultipleResponse = (RetrieveMultipleResponse)crmService.Execute(retrieveMultipleRequest);
                Guid contactId = Guid.Empty;
                foreach (Entity busEntity in retrieveMultipleResponse.EntityCollection.Entities)
                {
                    contactId = (Guid)busEntity["contactid"];   
                    break;
                }
                  
                return contactId;
            }
                  
            [Input("Enter Sender ")]
            [ReferenceTarget("sender ")]
            [Default("00000000-0000-0000-0000-000000000000", " sender ")]
            public InArgument<EntityReference> SenderId { get; set; }
    
            [Output("AccountId")]
            [ReferenceTarget("contact ")]
            [Default("00000000-0000-0000-0000-000000000000")]
            public OutArgument<EntityReference> AccountId { get; set; }
                
        }
    	
    }
    

    This builds without error.

    Thanks.


    Thursday, February 27, 2014 11:08 AM

Answers

  • Hi,
    I think you created a new project from scratch for the CRM 2011, am I right?
    In this case the plugin registration tool considers the dll as a brand new library, so it can't update an existing one. You can always remove the previous one and register again (however will be necessary to handle also all the workflows that contains this custom activity)


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

    • Marked as answer by crmNewbie1978 Friday, February 28, 2014 11:03 AM
    Thursday, February 27, 2014 12:07 PM

All replies

  • Hi,
    I think you created a new project from scratch for the CRM 2011, am I right?
    In this case the plugin registration tool considers the dll as a brand new library, so it can't update an existing one. You can always remove the previous one and register again (however will be necessary to handle also all the workflows that contains this custom activity)


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

    • Marked as answer by crmNewbie1978 Friday, February 28, 2014 11:03 AM
    Thursday, February 27, 2014 12:07 PM
  • Hi,

          Have you build the solution with snk file (strong name key) ?

    Thanks

    T.Vinoth

    Thursday, February 27, 2014 8:22 PM
  • Thanks for all the replies. I removed the existing one and am trying to register the updated one.

    I had to remove any dependencies before unregistering the existing assembly, but now I’m getting this error when trying to register the upgraded one:

    Invalid default value: The entity  sender  doesn't exist. Property: SenderId

    Here’s the code in the old version and the upgrade version.

    Original code:

            public static DependencyProperty senderProperty = DependencyProperty.Register("sender", typeof(string), typeof(MatchSenderWithExistingCustomerActivity));
            [CrmInput("Sender")]
            public string sender
            {
                get
                {
                    return (string)base.GetValue(senderProperty);
                }
    
                set
                {
                    base.SetValue(senderProperty, value);
                }
            }
    

    Upgraded code:

       [Input("Enter Sender ")]
            [ReferenceTarget("Sender ")]
            [Default("00000000-0000-0000-0000-000000000000", " Sender ")]
            public InArgument<EntityReference> SenderId { get; set; }
    

    I don’t really know if/what’s wrong with it, obviously I know it’s to do with the Sender property, but I don’t know what’s wrong with the upgraded code. I’ve checked the Sender attribute on Email, and the Schema Name has a capital S, but I also built the upgraded code with a lower case s, and that still produced the same error.

    Friday, February 28, 2014 11:06 AM
  • Thanks, I had that done.
    Friday, February 28, 2014 11:06 AM