错误 CS4032 开发 QnA bot C# 时
error CS4032 When developing QnA bot C#
我正在尝试通过发送第一条消息 "Hello user how are you?" 来让我的机器人问候用户。
这是我当前的代码:
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl));
var reply = message.CreateReply();
reply.Text = "Hello user how are you?";
await client.Conversations.ReplyToActivityAsync(reply);
}
这是我收到的错误:
Controllers\MessagesController.cs(55,17): error CS4032: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task<Activity>'. [D:\home\site\wwwroot\Microsoft.Bot.Sample.QnABot.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe" "D:\home\site\wwwroot\.\Microsoft.Bot.Sample.QnABot.csproj" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\wwwroot\.\.\"
任何帮助将不胜感激
HandleSystemMessage 必须是 async 并且 return type 必须是 Task 才能在内部使用 await。您还需要更改 HandleSystemMessage 的代码调用。如果调用方法是async,则需要像await HandleSystemMessage这样调用。如果不是,则需要等待。
我正在尝试通过发送第一条消息 "Hello user how are you?" 来让我的机器人问候用户。
这是我当前的代码:
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl));
var reply = message.CreateReply();
reply.Text = "Hello user how are you?";
await client.Conversations.ReplyToActivityAsync(reply);
}
这是我收到的错误:
Controllers\MessagesController.cs(55,17): error CS4032: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task<Activity>'. [D:\home\site\wwwroot\Microsoft.Bot.Sample.QnABot.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe" "D:\home\site\wwwroot\.\Microsoft.Bot.Sample.QnABot.csproj" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\wwwroot\.\.\"
任何帮助将不胜感激
HandleSystemMessage 必须是 async 并且 return type 必须是 Task 才能在内部使用 await。您还需要更改 HandleSystemMessage 的代码调用。如果调用方法是async,则需要像await HandleSystemMessage这样调用。如果不是,则需要等待。