首页 > 解决方案 > dc.BeginDialogAsync:“值不能为空。\n参数名称:选项”

问题描述

每次我运行await dc.BeginDialogAsync("sign-in");我都会得到这个没有意义的异常,因为其余参数是可选的。这让我超级困惑。这是我的代码:

public FlexoBot(ConversationState conversationState)
{
    this.dialogState = conversationState.CreateProperty<DialogState>("dialog-state");
    this.dialogs = new DialogSet(this.dialogState);

    // Make oauth card available to use for all handlers
    this.dialogs.Add(new OAuthPrompt("oauth", new OAuthPromptSettings() { ConnectionName = "flexo-auth" }));
    dialogs.Add(new WaterfallDialog("sign-in", new WaterfallStep[] {
        PromptSignIn,
        GreetUser,
    }));
}


protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
    var dc = await this.dialogs.CreateContextAsync(turnContext);
    foreach (var member in membersAdded)
    {
        if (member.Id != turnContext.Activity.Recipient.Id)
        {
            await dc.BeginDialogAsync("sign-in");
            // Throws: System.ArgumentNullException has been thrown "Value cannot be null.\nParameter name: options"
        }
    }
}

标签: c#azure-bot-service

解决方案


我终于弄明白了。这是因为我正在调用return step.PromptAsync("oauth", null);我的瀑布步骤之一。我将其更改为:

return step.PromptAsync("oauth", new PromptOptions { });

它现在有效。


推荐阅读