Issue
On K2 Management, the workflow instances in error all have the following error message:
Type 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' in Assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
Error Code
On the host server logs, you will see this error message logged at around the same time the workflow instance got into an Error state:
"Error","General","1","GeneralErrorMessage","SourceCode.Security.OAuth.Extensions.MicrosoftOnlineAppOnly.IssueAppOnlyToken","1 One or more errors occurred. InnerException: An internal server error has occurred. Retry the request. InnerException: The remote server returned an error: (400) Bad Request."
"Error","MessageBus","61012","ConnectionError","ExchangeWebServicesOrigin","61012 Exception from message source k2prd@sorkon.co.th: SourceCode.Hosting.Exceptions.AuthenticationException: Error issuing app only token. ---> System.AggregateException: One or more errors occurred. ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException: An internal server error has occurred. Retry the request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.HttpWebRequestWrapper.<GetResponseSyncOrAsync>d__2.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.HttpHelper.<SendPostRequestAndDeserializeJsonResponseAsync>d__0`1.MoveNext() --- End of inner exception stack trace --- at Microsoft.IdentityModel.Clients.ActiveDirectory.HttpHelper.<SendPostRequestAndDeserializeJsonResponseAsync>d__0`1.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<SendHttpMessageAsync>d__15.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<SendTokenRequestAsync>d__9.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<RunAsync>d__0.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenForClientCommonAsync>d__69.MoveNext()--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__1d.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at SourceCode.Security.OAuth.Extensions.MicrosoftOnlineAppOnly.IssueAppOnlyToken(OAuthResource oAuthResource, String resourceAudience) at SourceCode.Security.OAuth.Service.OAuthServiceLegacy.IssueOAuthTokenFromExtension(Guid primaryCredentialId, OAuthResource oAuthResource, String resourceAudience, Boolean appOnly, String refreshToken) at SourceCode.Security.OAuth.Service.OAuthServiceLegacy.IssueOAuthAppOnlyToken(Guid primaryCredentialId, OAuthResource oAuthResource, String resourceAudience, Boolean forceTokenRefresh) --- End of inner exception stack trace ---Server stack trace: at SourceCode.Security.OAuth.Service.OAuthServiceLegacy.IssueOAuthAppOnlyToken(Guid primaryCredentialId, OAuthResource oAuthResource, String resourceAudience, Boolean forceTokenRefresh) at SourceCode.Security.OAuth.Service.OAuthServiceLegacy.GetOAuthToken(Guid primaryCredentialId, Guid resourceId, String resourceAudience, Boolean forceTokenRefresh) at SourceCode.Security.OAuth.Service.OAuthServiceLegacy.GetOAuthAppOnlyToken(Guid resourceId, String resourceAudience, Boolean forceTokenRefresh) at SourceCode.Security.OAuth.Service.OAuthService.GetOAuthAppOnlyToken(Guid resourceId, String resourceAudience, Boolean forceTokenRefresh) at SourceCode.MessageBus.Server.TokenFactory.GetAccessToken(String resource, String audience) at SourceCode.MessageBus.Ews.ExchangeWebServicesConnectionStringBuilder.ExchangeServiceFactory(ITokenFactory tokenFactory) at SourceCode.MessageBus.Ews.ExchangeAutodiscover.Autodiscover(String emailAddress, ExchangeWebServicesConnectionStringBuilder builder) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase) at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData) at System.Func`3.EndInvoke(IAsyncResult result) at SourceCode.MessageBus.Ews.ExchangeWebServicesConnection.<>c__DisplayClass33_0.<AutodiscoverAsync>b__1(IAsyncResult result) InnerException: One or more errors occurred. InnerException: An internal server error has occurred. Retry the request. InnerException: The remote server returned an error: (400) Bad Request."
Resolution
- Edit the Exchange Online service instance on K2 Management > Features.
- Without making any changes, click on Update.
- When prompted to log in make sure to provide the credentials of a Global Admin account.
- If the update went through successfully, retry the workflow instances in error.