私は、ユーザーのグループに電子メールを送信するカスタムワークフローステップを作成しました。私は事前作成、電子メールを取得し、プログラム的にそれを送る:カスタムワークフローステップの一貫性のない動作
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