由于对象的当前状态

时间:2017-02-13 15:26:24

标签: botframework

  

发生了错误。   由于对象的当前状态,操作无效。      System.InvalidOperationException    在   Microsoft.Bot.Builder.Dialogs.Conversation&LT;&GT; c__3 1.<ResumeAsync>b__3_0() at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.Bot.Builder.Dialogs.Internals.ScoringDialogTask 1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.Bot.Builder.Dialogs.Internals.SerializingDialogTask.d__4 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.d__2 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.d__5 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.Bot.Builder.Dialogs.Conversation.d__5 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.<ResumeAsync>d__3 1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)在System.Runtime.CompilerServices.TaskAwaiter.GetResult()at   BotApplication.Controllers.OAuthCallbackController.d__0.MoveNext()   在   C:\ BotApplication \ BotApplication \ \控制器OAuthCallbackController.cs:行   55 ---从异常的先前位置开始的堆栈跟踪结束   扔了 - 在   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()    

当我在用户身份验证后尝试恢复对话时,就会发生这种情况。

我用这种方式调用身份验证:

在我的第一个对话框中:

  var message = context.MakeMessage();
    await context.Forward(new SecondDialog(), HandleOptions, message, CancellationToken.None);

然后在我的SecondDialog中有这个:

 var message = await argument;
                    MyStaticModel.toId = message.From.Id;
                    MyStaticModel.toName = message.From.Name;
                    MyStaticModel.fromId = message.Recipient.Id;
                    MyStaticModel.fromName = message.Recipient.Name;
                    MyStaticModel.serviceUrl = message.ServiceUrl;
                    MyStaticModel.channelId = message.ChannelId;
                    MyStaticModel.conversationId = message.Conversation.Id;
                    await context.Forward(new SimpleFacebookAuthDialog(message), ResumeAfterLogIn, message, CancellationToken.None);

在我的Facebook对话框中,我以这种方式制作恢复cookie:

 public SimpleFacebookAuthDialog(IMessageActivity msg)
        {
            ResumptionCookie = new ResumptionCookie(msg);
        }

当用户验证我处理身份验证时:

 public async Task<HttpResponseMessage> OAuthCallback([FromUri] string userId, [FromUri] string botId, [FromUri] string conversationId, [FromUri] string channelId, [FromUri] string serviceUrl, [FromUri] string locale, [FromUri] string code, [FromUri] string state, CancellationToken token)
        {
            //Get the resumption cookie
            Address address = new Address
                (
                    // purposefully using named arguments because these all have the same type
                    botId: FacebookHelpers.TokenDecoder(botId),
                    channelId: channelId, 
                    userId: FacebookHelpers.TokenDecoder(userId),
                    conversationId: FacebookHelpers.TokenDecoder(conversationId),
                    serviceUrl: FacebookHelpers.TokenDecoder(serviceUrl)

                );
            //var resumptionCookie = new ResumptionCookie(FacebookHelpers.TokenDecoder(userId), FacebookHelpers.TokenDecoder(botId), FacebookHelpers.TokenDecoder(conversationId), channelId, FacebookHelpers.TokenDecoder(serviceUrl), locale: locale);
            var resumptionCookie = new ResumptionCookie(address, userName: null, isGroup: false, locale: locale);

            // Exchange the Facebook Auth code with Access token
            var accessToken = await FacebookHelpers.ExchangeCodeForAccessToken(resumptionCookie, code, SimpleFacebookAuthDialog.FacebookOauthCallback.ToString());

            // Create the message that is send to conversation to resume the login flow
            var msg = resumptionCookie.GetMessage();
            msg.Text = $"token:{accessToken.AccessToken}";

            // Resume the conversation to SimpleFacebookAuthDialog

            await Conversation.ResumeAsync(resumptionCookie, msg, CancellationToken.None);

它落在最后一行代码上。恢复对话时。

任何帮助?

2 个答案:

答案 0 :(得分:0)

我解决了这个家伙。 我不知道真正的原因是什么,但是当我曾经等待争论并将其存储为消息时,以后参数在恢复cookie中是错误的。

现在,我将参数作为活动投射:

 var message = (Activity)context.Activity;

它运作正常。

问题解决了:))

答案 1 :(得分:0)

我在vs 2019中运行测试时遇到了相同的错误。 我可以通过清理解决方案,关闭vs并在重新启动vs-2019之后删除临时文件来解决此问题。 我点击了链接https://developercommunity.visualstudio.com/content/problem/875545/xunit-test-net-core-project-with-vs-2019-is-throwi.html