We have a solution that includes some custom process steps. Our customers add these steps that trigger various processes.
Recently, on CRM 2016+ and Dynamics 365, we have had customers report that when they add one of our specific steps, they receive the following error:
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Microsoft.Crm.Sdk.Picklist'
Other customers of ours have no problem. It is only 1 specific step that they add that produces the issues.
In that code, we do have a variety of InArgument values, for example:
[Input("Load User's Configuration")]
[Default("true")]
[RequiredArgument]
public InArgument<bool> UseUsersConfig { get; set; }
and several that are OptionSetValues
[Input("Decline Behavior")]
[AttributeTarget("new_thistheentityname", "new_thisisdeclinebehaviorfield")]
[Default("1")]
public InArgument<OptionSetValue> DeclineBehavior { get; set; }
Again, the error happens when the step is added, not when it is being run in a process. We ran this in an on-premises installation and turn off trace logs on the CRM instance on the server, and there is very little extra help with the error:
Error: Unable to cast object of type 'System.String' to type 'Microsoft.Crm.Sdk.Picklist'. Error Message: Unable to cast object of type 'System.String' to type 'Microsoft.Crm.Sdk.Picklist'. Source File: Not available Line Number: Not available Request URL: ascorpcrm2016/.../Workflow.asmx Stack Trace Info: [InvalidCastException: Unable to cast object of type 'System.String' to type 'Microsoft.Crm.Sdk.Picklist'.] at Microsoft.Crm.Workflow.ObjectModel.CustomStepBase.GetValue(Object crmValue, WorkflowAttributeType type) at Microsoft.Crm.Workflow.ObjectModel.CustomStepBase.GetPrimitiveExpression(CustomParameterInfoBase parameter, Object value) at Microsoft.Crm.Workflow.ObjectModel.CustomStepBase.SetParameters(CustomParameterInfoBase[] inputsInfo, CustomParameterInfoBase[] outputsInfo) at Microsoft.Crm.Workflow.ObjectModel.CustomActivityStep..ctor(WorkflowStep workflowStep, CustomActivityInfo activityInfo, CustomActivityParameterInfo[] inputsInfo, CustomActivityParameterInfo[] outputsInfo) at Microsoft.Crm.Workflow.ObjectModel.CustomActivityFactory.CreateCustomActivityStep(WorkflowStep workflowStep, Guid pluginTypeId) at Microsoft.Crm.Application.WebServices.WorkflowWebService.AddCustomActivityStep(String customActivityId, String parentId, String entityId, String descriptionXml) [2018-04-13 19:58:16.540] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread: 34 |Category: Platform |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: 163e4932-5f26-4c70-8a66-14170ea4de0f | ExceptionConverter.ConvertMessageAndErrorCode ilOffset = 0x208 at ExceptionConverter.ConvertMessageAndErrorCode(Exception exception, Int32& errorCode) ilOffset = 0x208 at ExceptionConverter.ToSingleFaultOther(Exception exception) ilOffset = 0x21 at ExceptionConverter.ToSingleFaultUnTyped(Exception exception) ilOffset = 0x38 at ExceptionConverter.ConvertToFault(Exception exception) ilOffset = 0x54 at ExceptionConverter.TryConvertToFaultExceptionInternal(Exception exception, Boolean createNewFaultException, FaultException`1& faultException) ilOffset = 0x6D at FaultHelper.ConvertToFault(Exception exception) ilOffset = 0x0 at ErrorInformation..ctor(Exception exception, Uri requestUrl, Boolean logError, IOrganizationContext context) ilOffset = 0x238 at AppWebService.CreateSoapException(Exception innerException) ilOffset = 0x3D at WorkflowWebService.AddCustomActivityStep(String customActivityId, String parentId, String entityId, String descriptionXml) ilOffset = 0x47 at RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) ilOffset = 0xFFFFFFFF at RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) ilOffset = 0x16 at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) ilOffset = 0x6C at LogicalMethodInfo.Invoke(Object target, Object[] values) ilOffset = 0x3F at WebServiceHandler.Invoke() ilOffset = 0xAE at WebServiceHandler.CoreProcessRequest() ilOffset = 0x134 at SyncSessionlessHandler.ProcessRequest(HttpContext context) ilOffset = 0x3F at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() ilOffset = 0x18D at HttpApplication.ExecuteStepImpl(IExecutionStep step) ilOffset = 0x64 at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) ilOffset = 0x15 at PipelineStepManager.ResumeSteps(Exception error) ilOffset = 0x27A at HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) ilOffset = 0x31 at HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) ilOffset = 0xB0 at PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) ilOffset = 0x131 at PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) ilOffset = 0x0 at UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) ilOffset = 0xFFFFFFFF at UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) ilOffset = 0xFFFFFFFF at PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) ilOffset = 0x1E7 at PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) ilOffset = 0x0 >System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #C0006CDE: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Microsoft.Crm.Sdk.Picklist'. > at Microsoft.Crm.Workflow.ObjectModel.CustomStepBase.GetValue(Object crmValue, WorkflowAttributeType type) > at Microsoft.Crm.Workflow.ObjectModel.CustomStepBase.GetPrimitiveExpression(CustomParameterInfoBase parameter, Object value) > at Microsoft.Crm.Workflow.ObjectModel.CustomStepBase.SetParameters(CustomParameterInfoBase[] inputsInfo, CustomParameterInfoBase[] outputsInfo) > at Microsoft.Crm.Workflow.ObjectModel.CustomActivityStep..ctor(WorkflowStep workflowStep, CustomActivityInfo activityInfo, CustomActivityParameterInfo[] inputsInfo, CustomActivityParameterInfo[] outputsInfo) > at Microsoft.Crm.Workflow.ObjectModel.CustomActivityFactory.CreateCustomActivityStep(WorkflowStep workflowStep, Guid pluginTypeId) > at Microsoft.Crm.Application.WebServices.WorkflowWebService.AddCustomActivityStep(String customActivityId, String parentId, String entityId, String descriptionXml)
Everything in the code on the Input values looks normal. We have other classes with very similar input arguments. The OptionSetValue Default values we are setting are all correct values. Removing the defaults does not change the behavior.
Any clue what is going on here?








