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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了这些错误与错误的语法或更新的包问题有关吗?相关的知识,希望对你有一定的参考价值。

请,我试图找出为什么仍然在我的代码下面收到这些错误。我做了一些更改后更新了一些包。我想知道新包是否会导致错误,或者它是否只是错误的语法。它是一个带有对话框的简单机器人,使用Bot Framework V4和Visual Studio 15.8.8。错误列表是:

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

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

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);
            }
        }
    }
}
答案

您正在OnTurnAsync中定义NameStepAsync和NameConfirmStepAsync。继续将OnTurnAsync之外的定义移到类级别。

以上是关于这些错误与错误的语法或更新的包问题有关吗?的主要内容,如果未能解决你的问题,请参考以下文章

php代码中的错误mysql更新命令

Numpy C++ 程序总是给出段错误(很可能滥用语法或类型)

需要有关我的更新查询的建议

(错误)SQL 代码 -530,错误外键 PAY$ID$U 的插入或更新值无效

如何在android的片段中设置应用程序上下文?

学习mysql插入返回语法错误