Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Updated custom workflow activity causing error when registering dll

$
0
0

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.



Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>