botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Exception: invalid need: expected Wait, have Done

Open xoposhiy opened this issue 10 years ago • 14 comments

I receive exception in emulator, when doing EchoBot with Bot Builder exactly as shown in documentation. (EchoDialog is copy pasted)

Message and stack-trace are not very informative. I can't understand what exactly is wrong in my code.

The same project works well if I do it without Bot Builder.

{
  "message": "An error has occurred.",
  "exceptionMessage": "invalid need: expected Wait, have Done",
  "exceptionType": "Microsoft.Bot.Builder.Internals.Fibers.InvalidNeedException",
  "stackTrace": "   в Microsoft.Bot.Builder.Internals.Fibers.Wait`1.ValidateNeed(Need need)\r\n   в Microsoft.Bot.Builder.Internals.Fibers.Wait`1.Microsoft.Bot.Builder.Internals.Fibers.IWait.Post[D](D item)\r\n   в Microsoft.Bot.Builder.Internals.Fibers.Extensions.Post[T](IFiber fiber, T item)\r\n   в Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.<Microsoft-Bot-Builder-Dialogs-Internals-IUserToBot-SendAsync>d__20.MoveNext()\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в Microsoft.Bot.Builder.Dialogs.Conversation.<SendAsync>d__2.MoveNext()\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   в Bot.Controllers.MessagesController.<Post>d__0.MoveNext() в C:\\work\\TsyaBot\\Bot\\Controllers\\MessagesController.cs:строка 22\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- Конец трассировка стека из предыдущего расположения, где возникло исключение ---\r\n   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   в System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}

xoposhiy avatar Apr 02 '16 15:04 xoposhiy

Try starting a new conversation by changing the conversation ID. You would see this exception if your code finished without calling something like context.Wait(MessageReceived). We'll work to improve the error message.

willportnoy avatar Apr 03 '16 00:04 willportnoy

Please re-open this issue if you've tried Will's suggestion and are still seeing an exception.

Stevenic avatar Apr 07 '16 00:04 Stevenic

I believe the solution is to clear your user profile by sending the framework a /deleteprofile message.

Good luck!

-r

rodzillarr avatar May 10 '16 17:05 rodzillarr

I had a similar issue and Will's solution worked, but I'm curious as to why this happens and how I can prevent the code from finishing before it calls context.Wait(MessageRecieved). Any ideas?

jamesrlewis avatar Jul 13 '16 17:07 jamesrlewis

I recently added a commit https://github.com/Microsoft/BotBuilder/commit/fa07e71774fc3e8ed7e943f22f48b891e806f32a (with some tests) to translate this exception to something more intelligible.

If you want to ensure that context.Wait(MessageReceived) is always called within a method, you can use a finally block or implement a IDisposable struct scoped to a using-block.

But it's not always what you want to do, because you may have some other method you'd like to received the next message into, to model some sort of state machine.

If you're using the LuisDialog, you might consider deriving from it and overriding the MessageReceived to call the base implementation then call context.Wait(MessageReceived), but that presumes you don't have more complicated state you want to track.

willportnoy avatar Jul 13 '16 21:07 willportnoy

okay. I opened another issue that's more specific to my problem than this thread. Thanks for your input

jamesrlewis avatar Jul 14 '16 14:07 jamesrlewis

@willportnoy I get this error when I call the bot from slack. It works in emulator after executing deleteprofile command but I am not able to get rid of this error when I call it from slack. How can I delete profile or clear state from previous conversation and start a new one?

Update: I tried to make the same conversation with bot using different slack user and it worked for the first time. It gives the same error again with this new user when I tried to do it 2nd time. The issue here I think is that I have got some error with both the users performing some action that only worked first time. The conversation got into a hanged state right then. Is there a way I can clear the earlier context of the user-bot conversation and make it a fresh start every time bot is called by any user?

niyatia avatar Jul 26 '16 20:07 niyatia

You need to add a space before /deleteprofile so that it's not interpreted by slack.

willportnoy avatar Jul 26 '16 22:07 willportnoy

I'm going to close this issue for now, but feel free to open a new issue with further questions.

willportnoy avatar Aug 04 '16 17:08 willportnoy

i tried making a small bot but facing this error....

{ "message": "An error has occurred.", "exceptionMessage": "Response status code does not indicate success: 400 (Bad Request).", "exceptionType": "System.Net.Http.HttpRequestException", "stackTrace": " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Luis.LuisService.d__4.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.Luis.Extensions.d__0.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.LuisDialog1.<MessageReceived>d__6.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.DialogTask.ThunkResume1.d__4.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.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.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.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop-PollAsync>d__7.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.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter.GetResult()\r\n at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.<ResumeAsync>d__3.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.DialogTask.ThunkResume1.d__4.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.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.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.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop-PollAsync>d__7.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.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.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.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__211.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.ReactiveDialogTask.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.LocalizedDialogTask.<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.ScoringDialogTask1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__61.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__61.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__61.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__4.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__2.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.GetResult()\r\n at chatbot.MessagesController.d__0.MoveNext() in c:\users\maantt1\documents\visual studio 2015\Projects\MajorProject\chatbot\Controllers\MessagesController.cs:line 25\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.Threading.Tasks.TaskHelpersExtensions.d__3`1.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.Web.Http.Controllers.ApiControllerActionInvoker.d__0.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.Web.Http.Controllers.ActionFilterResult.d__2.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.Web.Http.Filters.AuthorizationFilterAttribute.d__2.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.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }

my LUIS code is as follows....

using CourseData; using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Builder.Luis; using Microsoft.Bot.Builder.Luis.Models; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Web;

namespace chatbot { [LuisModel("", "")] [Serializable] public class LUISDialog : LuisDialog { [LuisIntent("Hi")] public async Task Hi(IDialogContext context, LuisResult result) { await context.PostAsync($"Hi user i am a bot, what info you want me to provide you"); context.Wait(MessageReceived); }

    public static Courses1 champs = new Courses1();
    [LuisIntent("CourseCount")]
    public async Task GetCourseCount(IDialogContext context, LuisResult result)
    {
        await context.PostAsync($"there are totally {champs.GetCourseCount()} courses.");
        context.Wait(MessageReceived);
    }
    
}

}

facing this same error whenever i tried to connect a bot using LUIS. please help me ASAP... stuck with this

enojo avatar Mar 01 '17 12:03 enojo

@enojo can you open a new top level issue for your LUIS question?

willportnoy avatar Mar 07 '17 02:03 willportnoy

I have a similar issue with an error message saying: Exception: invalid need: expected Wait, have Call It occures in the return function after authbot has authenticated and I am trying to forward the message into the mail dialog. My code:

 [Serializable]
    public class AuthDialog : IDialog<string>
    {
        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);
        }
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> item)
        {
            //original message if we need to resume
            var message = await item;

            //try to get access token
            var token = await context.GetAccessToken("https://graph.microsoft.com/");
            if (string.IsNullOrEmpty(token))
            {
                //invoke the AuthBot to help get authenticated
                await context.Forward(new AzureAuthDialog("https://graph.microsoft.com/"), this.resumeAfterAuth, message, CancellationToken.None);
            }
            else
            {
                //token exists...forward to GraphDialog
                await context.Forward(new RootDialog(), null, message, CancellationToken.None);
            }
        }

        private async Task resumeAfterAuth(IDialogContext context, IAwaitable<string> result)
        {
            //post the response message and then go back into the MessageReceivedAsync flow
            var message = await result;
            await context.PostAsync(message);

            //now that token exists...forward to GraphDialog
            await context.Forward(new RootDialog(), null, message, CancellationToken.None);
            context.Wait(MessageReceivedAsync);
        }
    }
}```

nornes avatar Jun 22 '17 12:06 nornes

@nornes Can you please open a new issue or post on stack overflow for this?

JasonSowers avatar Jun 22 '17 15:06 JasonSowers

@nornes : can you let me know how you have resolved the above issue??

I am also using AuthBot package for authentication, and my bot flow is similar to yours.

When access token is not present after authentication I get the same error as you i.e. Exception: invalid need: expected Wait, have Call.

Thanks in advance!

cwatch09 avatar Aug 21 '17 07:08 cwatch09