我做了一个自定义工作流程步骤,它将电子邮件发送给用户组。我采取预先创建的电子邮件和程序发送:自定义工作流程步骤不一致的行为
if (recepients.Entities.Any())
{
Entity email = service.Retrieve("email", mailId, new ColumnSet(true));
email.Attributes["to"] = recepients.Entities.ToArray();
service.Update(email);
SendEmailRequest sendEmail = new SendEmailRequest()
{
EmailId = mailId,
IssueSend = true
};
service.Execute(sendEmail);
}
的问题是 - 它工作在同步模式就好了,并抛出一个“无效的转换”异常,如果我转换成工作流程和异步尝试运行它。
这里什么跟踪日志服务器上的规定:在工作流程的转换结果发生
>System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #EBCA9EC1: System.InvalidCastException: Specified cast is not valid.
> at Microsoft.Crm.Common.ObjectModel.TrackingManager.GetNextTrackingToken(String subject, String& trackingToken)
> at Microsoft.Crm.Common.ObjectModel.EmailService.Send(Guid emailId, Boolean issueSend, String trackingToken, ExecutionContext context)
莫名其妙的错误。我应该在哪里寻找这个问题的根源?
at WorkflowToAsyncResultConverter.Convert(WorkflowSystemPausedResult wfResult) ilOffset = 0x23
at WorkflowToAsyncResultConverter.Convert() ilOffset = 0x9D
at WorkflowContext.EndProcessing(IGenericHandlerResult result) ilOffset = 0xC
at ActivityHost.CompleteWorkflow(IGenericHandlerResult result, WorkflowApplication activityInstance, ICommonWorkflowContext context) ilOffset = 0x70
at ActivityHostBase.OnWorkflowTerminated(WorkflowApplicationUnhandledExceptionEventArgs args, WorkflowApplication activityInstance, ICommonWorkflowContext context) ilOffset = 0x8F
at UnhandledExceptionEventHandler.OnStage1Complete(IAsyncResult lastResult, WorkflowApplication instance, Exception exception, Activity source, String sourceInstanceId) ilOffset = 0x46
at UnhandledExceptionEventHandler.Run(WorkflowApplication instance, Exception exception, Activity exceptionSource, String exceptionSourceInstanceId) ilOffset = 0x78
at WorkflowApplication.OnNotifyUnhandledException(Exception exception, Activity exceptionSource, String exceptionSourceInstanceId) ilOffset = 0x23
at ActivityExecutor.NotifyUnhandledException(Exception exception, ActivityInstance source) ilOffset = 0x18
at Scheduler.OnScheduledWork(Object state) ilOffset = 0x123
at SendOrPostThunk.UnhandledExceptionFrame(Object state) ilOffset = 0x0
at ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) ilOffset = 0x22
at IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) ilOffset = 0x5
at _IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) ilOffset = 0x3C
你如何在服务您的自定义工作流步骤它是否在执行用户的上下文中运行? –
@Henrik我使工厂脱离执行上下文,然后使用SYSTEM权限创建IOrganizationService实例。 – user3032348