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:
I have signed the Assembly and built the project.
I then registered the assembly in the Plugin Registration tool (V9)
I created the workflow in CRM:
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.
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. ---> 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.<>c__DisplayClass2_1.<Execute>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!