1
resposta

Erro ao criar o ambiente Development

Ao tentar criar um ambiente web de desenvolvimento ocorreu a seguinte falha no console:

     static void Main(string[] args)
    {
        var _repo = new LivroRepositorioCSV();

        IWebHost host = new WebHostBuilder()
            .UseKestrel()  
            .UseStartup<StartupDevelopment>() 
            .Build();
             host.Run();


        //ImprimeLista(_repo.ParaLer);
        //ImprimeLista(_repo.Lendo);
        //ImprimeLista(_repo.Lidos);
    }


public class StartupDevelopment
{
    public void ConfigureDevelopment(IApplicationBuilder app)
    {
        app.Run(LivrosParaLer);
    }

    public Task LivrosParaLer(HttpContext context)
    {
        //HttpContext contexto = new HttpContext(); // toda informação http é incapsulada dessa classe
        var _repo = new LivroRepositorioCSV();


        return context.Response.WriteAsync(_repo.ParaLer.ToString()); // para escrever            
    }
}

**Application startup exception: System.InvalidOperationException: A public method named 'ConfigureProduction' or 'Configure' could not be found in the 'Alura.ListaLeitura.App.StartupDevelopment' type. at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.FindMethod(Type startupType, String methodName, String environmentName, Type returnType, Boolean required) at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.FindConfigureDelegate(Type startupType, String environmentName) at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.LoadMethods(IServiceProvider hostingServiceProvider, Type startupType, String environmentName) at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass1_0.b__1(IServiceProvider sp) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup() at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Unhandled Exception: System.InvalidOperationException: A public method named 'ConfigureProduction' or 'Configure' could not be found in the 'Alura.ListaLeitura.App.StartupDevelopment' type. at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.FindMethod(Type startupType, String methodName, String environmentName, Type returnType, Boolean required) at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.FindConfigureDelegate(Type startupType, String environmentName) at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.LoadMethods(IServiceProvider hostingServiceProvider, Type startupType, String environmentName) at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass1_0.b__1(IServiceProvider sp) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup() at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at Alura.ListaLeitura.App.Program.Main(String[] args) in C:\Users\genilson.maceno\Dropbox\C-Sharp\Asp.NET Core\Alura.ListaLeitura\Alura.ListaLeitura.App\Program.cs:line 14

O C:\Program Files\dotnet\dotnet.exe (processo 17028) foi encerrado com o código -532462766. Pressione qualquer tecla para fechar esta janela...**

1 resposta

Olá Genilson, como vai?

Sentimos muito pela demora em te retornar.

Pelo código que compartilhou, acredito que falte um método para roteamento do projeto.

public Task Roteamento(HttpContext context)
        {
            var repo = new LivroRepositorioCSV();
            var caminhoAtendido = new Dictionary<string, RequestDelegate>
            {
                { "/Livros/ParaLer", LivrosParaLer },                
            };

            if (caminhoAtendido.ContainsKey(context.Request.Path))
            {
                var metodoRequestDelegate = caminhoAtendido[context.Request.Path];
                return metodoRequestDelegate.Invoke(context);
            }

            context.Response.StatusCode = 404;
            return context.Response.WriteAsync("Caminho inexistente!");
        }

O método ConfigureDevelopment continua semelhante ao método da classe Startup, veja:

public void Configure(IApplicationBuilder app)
    {
        app.Run(Roteamento);
    }

Abraços e bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software