AuthBot icon indicating copy to clipboard operation
AuthBot copied to clipboard

InvalidOperationException: Operation is not valid due to the current state of the object

Open Masssluis opened this issue 9 years ago • 1 comments

Hello , Everyone I am stuck into this issue.

  1. First i send message to Bot, Bot replies with sign-in card. 2.I sign-in successfully and paste magic number. 3.I wish to logout, I am successfully logged out. 4.Here start's the problem, I then go to my previous sign-in card and click on sign in card button (instead of sending hi/hello so that i could go to my AuthDialogHelper:IDialogContext(object) class.). 5.I get a login page but after loggin in , It crashes with an Error.

{ "message": "An error has occurred.", "exceptionMessage": "Operation is not valid due to the current state of the object.", "exceptionType": "System.InvalidOperationException", "stackTrace": " at Microsoft.Bot.Builder.Dialogs.Conversation.<>c__31.<ResumeAsync>b__3_0()\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ScoringDialogTask1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.SerializingDialogTask.d__41.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__21.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.d__21.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__51.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.d__51.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Conversation.d__51.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Conversation.<ResumeAsync>d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at AuthBot.Controllers.OAuthCallbackController.d__3.MoveNext()" }

Message Controller Code :

public async Task Post([FromBody]Activity activity) { if (activity.Type == ActivityTypes.Message) { RHDLuisDialog.Activity = activity; await Conversation.SendAsync(activity,() => new AuthDialogHelper()); // AuthDialogHelper is my Authentication Dialog Class. } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return response; }

AuthDialogHelper Class Code:

[Serializable] public class AuthDialogHelper : IDialog { public async Task StartAsync(IDialogContext context) { context.Wait(ProcessMessageAsync); }

    public async Task ProcessMessageAsync(IDialogContext context, IAwaitable<IMessageActivity> item)
    {
        var message = await item;

            if (string.IsNullOrEmpty(await context.GetAccessToken(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"])))
            {
                //Don't have an Access token then get it...
                await context.Forward(new AzureAuthDialog(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]), this.ProcessAuthResultAsync, message, System.Threading.CancellationToken.None);
            }
            else
            {
                await context.Forward(new RHDLuisDialog(), ResumeAfterAsync, message, CancellationToken.None);
            } 
    }

    public async Task ProcessAuthResultAsync(IDialogContext context, IAwaitable<string> result)
    {
        //Get the result from AzureAuthDialog
      
        var message = await result;
        context.Wait(this.ProcessMessageAsync);
       
    }

    public async Task ResumeAfterAsync(IDialogContext context, IAwaitable<Object> result)
    {
        var message = await result;
        context.Wait(this.ProcessMessageAsync);
    }
}

The problem is when i send "hi" for secound time and get sign-in card it works perfectly because hi->messagesController->AuthDialogHelper and it works perfectly. But when I directly go and tap on pervious sign-in card without sending any "Hi/Hello" it crashes into the above error after authentication but gets access token.

Kindly, provide your valuable suggestions.

Thanks.

Masssluis avatar Jan 01 '17 12:01 Masssluis

This library doesn't deal with re-entering old cards. For security reasons I don't think it would be a good idea to let the user click on the same car that has already been used for authentication. In fact I was planning to expire that quicker to be honest.

matvelloso avatar May 18 '17 20:05 matvelloso