0
votes

I am having an issue with a crm 2011 custom workflow activity I have created. 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'. 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)

And after sandboxing...

Workflow paused due to error:

Unhandled Exception: System.ArgumentNullException: Value cannot be 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, IList1& validationErrors) at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack1& activitiesRemaining, ActivityCallStack parentChain, IList1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback) at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList1& 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)

None of these errors make any sense to me since they seem to be an issue with CRM itself and not with my code. 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. 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! 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. Any thoughts on why that might be?

1
Sandboxed workflow activities ARE supported in CRM 2011. In fact CRM 2011 was the first release that they were supported and thus enabled deploying custom code to CRM Online.Josh Painter
You're right, my fault. Microsoft Dynamics CRM Online support for sandbox execution of custom workflow activities was added in the Microsoft Dynamics CRM December 2012 Service Update.Henk van Boeijen

1 Answers

0
votes

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. When you update the build number, this tells CRM's async services to reload your custom assembly.

Try unregistering the workflow from CRM and then re-registering it. 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.