【问题标题】:Can you use microsoft bot framework 4.9 to build a bot with core 3.1?你可以使用 microsoft bot framework 4.9 来构建一个带有 core 3.1 的机器人吗?
【发布时间】:2020-08-31 07:59:34
【问题描述】:

我使用 Bot Framework 模板创建了一个 EchoBot,安装了 bot Framework 4.9,然后将目标 .Net 版本更改为 Core 3.1。现在,我收到以下错误:

System.InvalidOperationException H结果=0x80131509 消息=端点路由不支持“IApplicationBuilder.UseMvc(...)”。要使用 'IApplicationBuilder.UseMvc' 在 'ConfigureServices(...) 中设置 'MvcOptions.EnableEndpointRouting = false'。 来源=Microsoft.AspNetCore.Mvc.Core

如何解决这个错误?

【问题讨论】:

  • 你可以在没有敏感信息的情况下将你的源代码上传到 giuhub 吗?因为你的项目环境我们不清楚,所以没有办法给出针对性的解决方案。

标签: c# .net asp.net-core botframework


【解决方案1】:

https://marketplace.visualstudio.com/items?itemName=BotBuilder.botbuilderv4 的当前 vsix 模板具有 Core 3.1 Echobot 模板。如果您还没有,请更新到新模板。

话虽如此,您不能只更改目标 .Net 版本。 2.1 中的一些方法在 3.1 中不再存在(您已经发现)。两个启动文件的快速比较显示:

2.1:

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseHsts();
    }

    app.UseDefaultFiles();
    app.UseStaticFiles();
    app.UseWebSockets();
    //app.UseHttpsRedirection();
    app.UseMvc();
}

app.UseMvc(); 是您的机器人遇到问题的地方。 3.1版本如下:

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseDefaultFiles()
        .UseStaticFiles()
        .UseWebSockets()
        .UseRouting()
        .UseAuthorization()
        .UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

    // app.UseHttpsRedirection();
}

所以要么更新你的模板,要么更新你的 Startup.cs 文件。

【讨论】:

    猜你喜欢
    • 2021-10-01
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多