简体   繁体   English

Dynamics CRM 2011自定义工作流活动问题

[英]Dynamics CRM 2011 Custom Workflow Activity Issue

I am having an issue with a crm 2011 custom workflow activity I have created. 我创建的crm 2011自定义工作流程活动遇到问题。 The workflow activity is part of a workflow that cancels and renews contracts. 工作流程活动是取消和续订合同的工作流程的一部分。 The activity works after restarting the async services but quickly stops working afterwards. 该活动在重新启动异步服务后起作用,但是此后很快就停止工作。 I get a different error message depending on if the assembly is sandboxed or not. 根据程序集是否被沙盒化,我会收到不同的错误消息。 Below is the original message I received before deciding to try sandboxing the assembly. 以下是我决定尝试对程序集进行沙箱处理之前收到的原始消息。

Workflow paused due to error: 工作流程因错误而暂停:

Unhandled Exception: System.TypeLoadException: Could not load type 'Microsoft.Xrm.Sdk.OrganizationRequestCollection' from assembly 'Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 未处理的异常:System.TypeLoadException:无法从程序集“ Microsoft.Xrm.Sdk,版本= 5.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35”中加载类型“ Microsoft.Xrm.Sdk.OrganizationRequestCollection”。 at ANHWP_WF_Library.CreateWarrantyPolicy.Execute(CodeActivityContext executionContext) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) 在ANHWP_WF_Library.CreateWarrantyPolicy.Execute(在System.Activities.CodeActivity.InternalExecute(ActivityInstance实例,ActivityExecutor执行器,BookmarkManager书签管理器)在System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkbook.ExecuteBody(ActivityExmarkutor的执行者,BookManager

And after sandboxing... 然后在沙箱之后...

Workflow paused due to error: 工作流程因错误而暂停:

Unhandled Exception: System.ArgumentNullException: Value cannot be null. 未处理的异常:System.ArgumentNullException:值不能为null。 Parameter name: type at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at Microsoft.Crm.Workflow.Services.ActivityReferenceService.InitializeActivity(ActivityReference activityReference) at Microsoft.Xrm.Sdk.Workflow.Activities.ActivityReference.CacheMetadata(NativeActivityMetadata metadata) at System.Activities.NativeActivity.OnInternalCacheMetadata(Boolean createEmptyBindings) at System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings, IList 1& validationErrors) at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack 1& activitiesRemaining, ActivityCallStack parentChain, IList 1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback) at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList 参数名称:Microsoft.Crm.Workflow.Services.ActivityReferenceService.InitializeActivity(ActivityReference activityReference)的System.Activator.CreateInstance(Type类型)的System.Activator.CreateInstance(Type类型,布尔非公共)类型。 System.Activities.NativeActivity.OnInternalCacheMetadata(Boolean createEmptyBindings)在System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings,IList 1& validationErrors) at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack Boolean createEmptyBindings,IList 1& validationErrors) at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack 1和活动1& validationErrors) at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack ActivityCallStack parentChain,IList 1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback) at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList 1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback) at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList 1& validationErrors) at System.Activities.ActivityUtilities.CacheRootMetadata(Activity activity, LocationReferenceEnvironment hostEnvironment, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList`1& validationErrors) at System.Activities.Hosting.WorkflowInstance.ValidateWorkflow(WorkflowInstanceExtensionManager extensionManager) at System.Activities.WorkflowApplication.EnsureInitialized() at System.Activities.WorkflowApplication.Enqueue(InstanceOperation operation, Boolean push) at System.Activities.WorkflowApplication.WaitForTurn(InstanceOperation operation, TimeSpan timeout) at System.Activities.WorkflowApplication.InternalRun(TimeSpan timeout, Boolean isUserRun) at Microsoft.Crm.Workflow.ActivityHost.StartWorkflowExecution(Activity workflow, ICommonWorkflowContext context) at Microsoft.Crm.Workflow.ActivityHostBase.StartWorkflow(ICommonWorkflowContext context, Activity preLoadedActivity) 1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback) at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList位于System.Activities.ActivityUtilities.CacheRootMetadata(Activity活动,LocationReferenceEnvironment hostEnvironment,ProcessActivityTreeOptions选项,ProcessActivityCallback回调,IList`1&validationErrors)位于System.Activities.Hosting.WorkingInstance.ValidateWorkflow(WorkflowInstanceExtension) System.Activities.WorkflowApplication.Enqueue(InstanceOperation操作,布尔值推送)处的Activities.WorkflowApplication.EnsureInitialized()在System.Activities.WorkflowApplication.InternalRun(TimeSpan超时,布尔值)处System.Activities.WorkflowApplication.WaitForTurn(InstanceOperation操作,TimeSpan超时) Microsoft.Crm.Workflow.ActivityHost.StartWorkflowExecution(活动工作流,ICommonWorkflowContext上下文)处的isUserRun)(Microsoft.Crm.Workflow.ActivityHostBase.StartWorkflow(ICommonWorkflowContext上下文,活动preLoadedActivity)

None of these errors make any sense to me since they seem to be an issue with CRM itself and not with my code. 这些错误对我来说都没有意义,因为它们似乎是CRM本身的问题,而不是我的代码的问题。 Other activities in the same assembly still run fine so it has to be an issue with my activity. 同一程序集中的其他活动仍然运行良好,因此我的活动必定是一个问题。 Has anyone seen this before? 谁看过这个吗? Thanks in advance. 提前致谢。

Edit: 编辑:

So the issue sees to be related to my desire to re-use code (Like any good developer would do). 因此,问题似乎与我重用代码的愿望有关(就像任何优秀的开发人员一样)。 What I had done was created a service class to handle the cancelling and renewal of contracts so that I could call the same code from different parts of the workflow activity. 我所做的是创建了一个服务类来处理合同的取消和续签,以便可以从工作流活动的不同部分调用相同的代码。 Now it seems that CRM did not like this very much. 现在看来,CRM不太喜欢这种方式。 I tried moving the methods out of the service class and into some private methods inside the workflow activity class but I was getting the same errors. 我尝试将方法移出服务类,并移入工作流活动类内的某些私有方法,但我遇到了相同的错误。 Eventually I decided to see what would happen if I placed every line of code inside the actual Execute method of the workflow activity and viola! 最终,我决定看看如果将每一行代码放在工作流活动和中提琴的实际Execute方法中会发生什么情况! No more errors. 没有更多的错误。 This seems a little bit strange to me because from where I'm sitting instantiating and calling other classes should work fine in the same assembly as long as the classes are instantiated from within the execute method and are not globally defined. 这对我来说似乎有点奇怪,因为从我所在的位置实例化并调用其他类应该在同一程序集中正常工作,只要这些类是从execute方法中实例化的,并且未全局定义。 Any thoughts on why that might be? 有什么想法为什么呢?

Are you changing the custom activity's code (specifically inputs/outputs?) If so, you need to make sure to increment the build number of the custom assembly before you re-register it in CRM. 您是否要更改自定义活动的代码(特别是输入/输出?)。如果是这样,则需要确保增加自定义程序集的内部版本号,然后才能在CRM中重新注册它。 When you update the build number, this tells CRM's async services to reload your custom assembly. 当您更新内部版本号时,这会告诉CRM的异步服务重新加载您的自定义程序集。

Try unregistering the workflow from CRM and then re-registering it. 尝试从CRM取消注册工作流程,然后重新注册。 Unfortunately you will have to remove the custom step from any workflow activities before you unregister it. 不幸的是,在取消注册之前,您必须从所有工作流程活动中删除自定义步骤。 If you ever change the inputs/outputs of a custom workflow activity, you'll have to go through the same unregister/register process. 如果您更改了自定义工作流程活动的输入/输出,则必须执行相同的注销/注册过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM