这些错误与语法错误或更新的软件包问题有关吗?

时间:2018-10-25 14:55:51

标签: c# botframework

请,我试图弄清楚为什么仍然在下面的代码中收到这些错误。在进行一些更改之前,我更新了一些软件包。我想知道新软件包是否会导致错误或语法错误。这是一个使用Bot Framework V4和Visual Studio 15.8.8的带有对话框的简单bot。错误列表为:

  • 私有修饰符对此项目无效
  • 私有修饰符对此项目无效
  • 对于当前上下文,名称NameStepAsync和NameConfirmStepAsync不存在。
  • 无法声明本地或参数名称的cancelingToken。
  • 软件包还原失败。
  • 检测到的软件包降级。

所有错误代码都链接到不同的示例。我可以自己解决其他错误。我将感谢所有反馈,并可以提供更多信息,但是请帮助我。

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
using Microsoft.Bot.Builder.Dialogs;

namespace IcidBotOne
{

    public class EchoWithCounterBot : IBot
    {

        private DialogSet _dialogs;
        private readonly EchoBotAccessors _accessors;
        private readonly ILogger _logger;


        public EchoWithCounterBot(EchoBotAccessors accessors)


        {
            // Set the _accessors
            _accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors));
            // The DialogSet needs a DialogState accessor, it will call it when it has a turn context.
            _dialogs = new DialogSet(accessors.ConversationDialogState);
            // This array defines how the Waterfall will execute.
            var waterfallSteps = new WaterfallStep[]
            {
                NameStepAsync,
                NameConfirmStepAsync,
            };
            // Add named dialogs to the DialogSet. These names are saved in the dialog state.
            _dialogs.Add(new WaterfallDialog("details", waterfallSteps));
            _dialogs.Add(new TextPrompt("name"));
        }

        /// <summary>
        /// Every conversation turn for our Echo Bot will call this method.
        /// There are no dialogs used, since it's "single turn" processing, meaning a single
        /// request and response.
        /// </summary>
        /// <param name="turnContext">A <see cref="ITurnContext"/> containing all the data needed
        /// for processing this conversation turn. </param>
        /// <param name="cancellationToken">(Optional) A <see cref="CancellationToken"/> that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> that represents the work queued to execute.</returns>
        /// <seealso cref="BotStateSet"/>
        /// <seealso cref="ConversationState"/>
        /// <seealso cref="IMiddleware"/>
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Handle Message activity type, which is the main activity type for shown within a conversational interface
            // Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
            // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                // Get the conversation state from the turn context.
                var state = await _accessors.CounterState.GetAsync(turnContext, () => new CounterState());

                // Bump the turn count for this conversation.
                state.TurnCount++;
                if (!state.SaidHello)
                {
                    // MARCUS: Handlle the Greeting
                    string strMessage = $"Hello World! {System.Environment.NewLine}";
                    strMessage += "Talk to me and I will repeat it back!";
                    await turnContext.SendActivityAsync(strMessage);

                    // MARCUS: Set SaidHello
                    state.SaidHello = true;
                }

                // Run the DialogSet - let the framework identify the current state of the dialog from
                // the dialog stack and figure out what (if any) is the active dialog.
                var dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken);
                var results = await dialogContext.ContinueDialogAsync(cancellationToken);
                // If the DialogTurnStatus is Empty we should start a new dialog.
                if (results.Status == DialogTurnStatus.Empty)
                {
                    await dialogContext.BeginDialogAsync("details", null, cancellationToken);
                }

                // Set the property using the accessor. OK
                await _accessors.CounterState.SetAsync(turnContext, state);

                // Save the new turn count into the conversation state. OK
                await _accessors.ConversationState.SaveChangesAsync(turnContext);
            }

            private static async Task<DialogTurnResult> NameStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
            {
            // Running a prompt here means the next Waterfall
            // will be run when the user response is received.
                    return await stepContext.PromptAsync("name", new PromptOptions { Prompt = MessageFactory.Text("What is your name?") }, cancellationToken);
            }

            private async Task<DialogTurnResult> NameConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
            {
                    // We can send messages to the user at any point in the WaterfallStep.
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Hello {stepContext.Result}!"), cancellationToken);
                    // WaterfallStep always finishes with the end of the Waterfall or with another dialog,
                    // here it is the end.
                    return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您要在OnTurnAsync中定义NameStepAsync和NameConfirmStepAsync。继续并将其定义移至OnTurnAsync之外的类级别。