首页 > 解决方案 > 你可以使用 microsoft bot framework 4.9 来构建一个带有 core 3.1 的 bot 吗?

问题描述

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

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

如何修复此错误?

标签: c#.netasp.net-corebotframework

解决方案


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 文件。


推荐阅读