您可以使用 Microsoft Bot Framework 4.9 构建具有核心 3.1 的机器人吗?



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

System.InvalidOperationException HResult=0x80131509 Message=Endpoint Routing 不支持"IApplicationBuilder.UseMvc(...("。要使用"IApplicationBuilder.UseMvc",请在"ConfigureServices(...("中设置"MvcOptions.EnableEndpointRouting = false"。 Source=Microsoft.AspNetCore.Mvc.Core

如何修复此错误?

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();
}

因此,请更新模板或更新启动.cs文件。

最新更新