Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 3.1 .net核心Ocelot是一个名为';配置开发';或';配置';找不到_Asp.net Core 3.1_.net Core 3.1_Ocelot - Fatal编程技术网

Asp.net core 3.1 .net核心Ocelot是一个名为';配置开发';或';配置';找不到

Asp.net core 3.1 .net核心Ocelot是一个名为';配置开发';或';配置';找不到,asp.net-core-3.1,.net-core-3.1,ocelot,Asp.net Core 3.1,.net Core 3.1,Ocelot,下面的代码属于.net核心web api,我称之为OcelotApiGateway 我通过OcelotApiGateway上的nuget package manager安装了Ocelot 16.0.1 这是我的程序。cs using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; namespace OcelotApiGatew

下面的代码属于.net核心web api,我称之为OcelotApiGateway

我通过OcelotApiGateway上的nuget package manager安装了Ocelot 16.0.1

这是我的程序。cs

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace OcelotApiGateway
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureAppConfiguration((host, config) => config.AddJsonFile("ocelot.json"));
                    webBuilder.UseStartup<Startup>();
                });
    }
}
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;

namespace OcelotApiGateway
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddOcelot(Configuration);
        }

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

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            await app.UseOcelot();
        }
    }
}
但是在“
CreateHostBuilder(args).Build().Run()的行中Program.cs
中,发生此错误

System.InvalidOperationException:'在'OcelotApiGateway.Startup'类型中找不到名为'ConfigureDevelopment'或'Configure'的公共方法。'


我解决了这个问题,这是我的错。当我在Configure()方法中添加
wait
时,Visual studio自动更改了此方法。如下。我后来意识到了这一点

public async Task ConfigureAsync(IApplicationBuilder app, IWebHostEnvironment env)
此方法必须:

public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)

不要使用
异步void
!您的代码之所以有效,是因为在Ocelot启动中没有真正的异步工作。但如果它改变了,你的服务就会失败。