Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

Posted on by 65

hello, 

I am having a lot of trouble debugging a custom workflow for D365 V9 On Premise. I have researched for hours without any luck, please help. I created a custom workflow project with the .NET Framework 4.6.2. The code is as follows:

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;

namespace UpdateQuoteTasks_CWA
{
public class UpdateQuoteTasks_CWA : CodeActivity
{/// <summary>
/// When the Quote CSC/PP (TM) (1) field is updated, the workflow will find the open Quoting tasks assigned to the PreImage CSC1 and assign it to the post CSC1. Same goes for CSC2
///
/// </summary>
/// <param name="executionContext"></param>
///
[Input("Dummy Argument for Profiler")]
[Default("Dummy Argument for Profiler")]
public InArgument<string> DummyArgument { get; set; }

private const string PreBusinessEntity = "PreBusinessEntity";
private const string PostBusinessEntity = "PostBusinessEntity";

protected override void Execute(CodeActivityContext executionContext)
{
try
{
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService orgservice = serviceFactory.CreateOrganizationService(context.UserId);
OrganizationServiceContext orgcontext = new OrganizationServiceContext(orgservice);


Entity Quote = (from q in orgcontext.CreateQuery("quote") where q.GetAttributeValue<Guid>("quoteid") == context.PrimaryEntityId select q).FirstOrDefault();

Entity preImage = context.PreEntityImages[PreBusinessEntity];
Entity postImage = context.PostEntityImages[PostBusinessEntity];

if(preImage != null && postImage != null)
{
if((preImage.Contains("cti_accountmanageruserid") && postImage.Contains("cti_accountmanageruserid")) && (preImage.GetAttributeValue<EntityReference>("cti_accountmanageruserid") != postImage.GetAttributeValue<EntityReference>("cti_accountmanageruserid")))
{
EntityReference PreCSC1 = preImage.GetAttributeValue<EntityReference>("cti_accountmanageruserid");
EntityReference PostCSC1 = postImage.GetAttributeValue<EntityReference>("cti_accountmanageruserid");

List<Entity> TaskstoUpdate = (from task in orgcontext.CreateQuery("task")
where task.GetAttributeValue<EntityReference>("regardingobjectid").Id == Quote.GetAttributeValue<Guid>("quoteid")
where task.GetAttributeValue<OptionSetValue>("cti_task").Value == 41
where task.GetAttributeValue<OptionSetValue>("statecode").Value == 0
where task.GetAttributeValue<EntityReference>("ownerid").Id == PreCSC1.Id
select task).ToList();
if(TaskstoUpdate.Count > 0)
{
foreach(Entity Task in TaskstoUpdate)
{
Entity TasktoUpdate = new Entity("task", Task.GetAttributeValue<Guid>("activityid"));
TasktoUpdate["ownerid"] = PostCSC1;
orgservice.Update(TasktoUpdate);
}
}

}
if ((preImage.Contains("cti_pp2") && postImage.Contains("cti_pp2")) && (preImage.GetAttributeValue<EntityReference>("cti_pp2") != postImage.GetAttributeValue<EntityReference>("cti_pp2")))
{
EntityReference PreCSC2 = preImage.GetAttributeValue<EntityReference>("cti_pp2");
EntityReference PostCSC2 = postImage.GetAttributeValue<EntityReference>("cti_pp2");

List<Entity> TaskstoUpdate = (from task in orgcontext.CreateQuery("task")
where task.GetAttributeValue<EntityReference>("regardingobjectid").Id == Quote.GetAttributeValue<Guid>("quoteid")
where task.GetAttributeValue<OptionSetValue>("cti_task").Value == 41
where task.GetAttributeValue<OptionSetValue>("statecode").Value == 0
where task.GetAttributeValue<EntityReference>("ownerid").Id == PreCSC2.Id
select task).ToList();
if (TaskstoUpdate.Count > 0)
{
foreach (Entity Task in TaskstoUpdate)
{
Entity TasktoUpdate = new Entity("task", Task.GetAttributeValue<Guid>("activityid"));
TasktoUpdate["ownerid"] = PostCSC2;
orgservice.Update(TasktoUpdate);
}
}
}

}
}
catch (FaultException<OrganizationServiceFault> e)
{
throw;
}
catch (InvalidWorkflowException e)
{
throw;
}
catch (Exception e)
{
throw;
}
}

}
}

I have installed the NuGet packages:

pastedimage1607546166780v1.png

I have signed the Assembly and built the project. 

I then registered the assembly in the Plugin Registration tool (V9)

pastedimage1607546241852v2.png

I created the workflow in CRM:

pastedimage1607546286091v3.png

I need to debug this as it is finding more tasks to update than specified. I then open the Plugin Profiler and select my workflow and steps. 

pastedimage1607546673551v4.png

Then I get this error: 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unable to load plug-in assembly.
Detail: <OrganizationServiceFault xmlns="">schemas.microsoft.com/.../Contracts" xmlns:i="">www.w3.org/.../XMLSchema-instance">
<ActivityId>da69286f-44c4-4eb9-81e4-6333ac6e7126</ActivityId>
<ErrorCode>-2147204719</ErrorCode>
<ErrorDetails xmlns:a="">schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<a:key>ApiExceptionSourceKey</a:key>
<a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiOriginalExceptionKey</a:key>
<a:value i:type="b:string" xmlns:b="">www.w3.org/.../XMLSchema">Microsoft.Crm.CrmException: Unable to load plug-in assembly. ---&gt; Microsoft.Crm.CrmException: Unable to load plug-in assembly.
at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.LoadCrmPluginAssemblyMetadata(IBusinessEntity pluginAssembly, ExecutionContext context, Boolean loadAllMetadata)
at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.RetrieveAssemblyMetadata(IBusinessEntity pluginAssembly, ExecutionContext context, Boolean retrieveFromExisting, Boolean forSystemAssembly)
at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.ValidateOperation(String operationName, IBusinessEntity entity, ExecutionContext context)
at Microsoft.Crm.ObjectModel.SdkEntityServiceBase.CreateInternal(IBusinessEntity entity, ExecutionContext context, Boolean verifyAction)
--- End of inner exception stack trace ---
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.Pipeline.&lt;&gt;c__DisplayClass2_1.&lt;Execute&gt;b__0()</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiStepKey</a:key>
<a:value i:type="b:guid" xmlns:b="">schemas.microsoft.com/.../a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiDepthKey</a:key>
<a:value i:type="b:int" xmlns:b="">www.w3.org/.../a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiActivityIdKey</a:key>
<a:value i:type="b:guid" xmlns:b="">schemas.microsoft.com/.../a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiPluginSolutionNameKey</a:key>
<a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiStepSolutionNameKey</a:key>
<a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<HelpLink i:nil="true" />
<Message>Unable to load plug-in assembly.</Message>
<Timestamp>2020-12-09T20:44:45.9049648Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault>
<ActivityId>da69286f-44c4-4eb9-81e4-6333ac6e7126</ActivityId>
<ErrorCode>-2147204719</ErrorCode>
<ErrorDetails xmlns:a="">schemas.datacontract.org/.../System.Collections.Generic" />
<HelpLink i:nil="true" />
<Message>Unable to load plug-in assembly.</Message>
<Timestamp>2020-12-09T20:44:45.9049648Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<OriginalException i:nil="true" />
<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 PluginProfiler.Library.ProfilerManagementUtility.CreateWorkflowAssembliesAndTypes(CrmServiceClient service, ActivityAssemblyCompilerConfiguration configuration, Dictionary`2 types, OptionSetValue isolationMode, DateTime lastModified, IEnumerable`1 mappedAssemblies)
at PluginProfiler.Library.ProfilerManagementUtility.InstrumentWorkflowSteps(CrmServiceClient service, Guid workflowId, String keyFileName, CustomActivityStep[] workflowSteps)
at PluginProfiler.Library.ProfilerManagementUtility.EnableWorkflow(CrmServiceClient service, String overrideKeyFileName, Guid workflowId, Boolean persistToEntity, String persistenceSessionKey, Boolean includeSecureInformation, Boolean isContextReplay, CustomActivityStep[] workflowSteps)
at Microsoft.Crm.Tools.PluginRegistration.CommonControls.ProfilerSettingsViewModel.btnOk_Click()

Any ideas? I have made sure that the Microsoft.Xrm.Sdk.Workflow.dll is the same version in the plugin registation folder and the NuGet package. The only thing I can think of is that the plugin registion folder does not have the Microsoft.Xrm.Sdk.Client.dll. But I don't know how to get it or how to not use it in my code. 

Any other suggestions? Other than tracing please.... 

Thank you! 

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

    Hello,

    I'm afraid that you would not be able to debug the custom workflow activity this way - because it's just broken.

    My recommendation:

    1. Don't use Custom Workflow Activities, use Custom action with input/output parameters and with the plugin on the back that will do whatever you need. You will be able to call an action from the workflow the same way as you call Custom Workflow Assemblies.

    2. If you want to use CWA anyway you could use a tracing service to trace information.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

    Have you tried making it a manual workflow and manually running it, then check workflow log and Plug-in trace log (if you have this setup).

  • KP838 Profile Picture
    KP838 65 on at
    RE: Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

    Hi,

    There is no error without the profiler. This workflow is supposed to run when the Project Manager on the Quote is changed (user lookup field). When this happens, the workflow is supposed to find all the open Tasks for that Quote that were assigned to the previous User in that field, and reassign the those Tasks to the person updated in the PM field. Instead, the workflow is reassigning ALL the open Tasks for the Quote to the person updated in the PM field, not just the ones that were assigned to the previous PM specified. Without debugging, it is hard to tell where the linq query is going wrong and why it is updating all the Tasks instead of just the ones brought back by the Query.

    Thanks for your help!

    Kate

  • semosby Profile Picture
    semosby 230 on at
    RE: Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

    What was the error thrown when you ran without the profiler?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

    Not sure if this is still an issue, but I always use sandbox mode, Id try that and see if it helps anything.

  • KP838 Profile Picture
    KP838 65 on at
    RE: Cannot debug custom workflow in plugin registration tool - Unable to load assembly error

    I forgot to mention that I registered the assembly with no isolation mode on the database.

    pastedimage1607547563840v1.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans