Solucionado (ver solução)
Solucionado
(ver solução)
5
respostas

Erro com Migratios .Net 2 ou .Net 7 - Contexto

Mudei para o .Net7, porque o 2 está dando um erro que não aparece no console e sim no roda pé. Diz que deu um erro inesperado. Tentei ver no fórum, para ver se eu achava a solução. Mas não achei nada. Aí a solução foi mudar para o 7 e dar um update nos pacotes.

O engraçado é que agora está dando o mesmo erro dos cursos passados, mas ainda não consegui entender como funciona o erro para corrigir de vez.

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Os erros passado eu corrigir usando o código Update-Database, mas dessa vez não funcionou. https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=vs

E outra pergunta, esse projeto não tem contexto? Onde eu coloco a senha e o nome dá minha conexão com o DB?

=> O projeto é do Curso de Selenium WebDriver e C# parte 1: testes da sua web app

5 respostas

Com um projeto novo, mudei tudo para o .Net 7 e atualizei os pacotes. Depois add o Microsoft.EntityFrameworkCore.Design no .WebApp E as Migrations rodaram de boas...

Tive ajuda do pessoal do Discord @Bruno Aragão

Deu certo, mas o servidor está dando status 500

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Insira aqui a descrição dessa imagem para ajudar na acessibilidade As duas URLs estão voltando 500.

fail: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[3]
      The view 'Index' was not found. Searched locations: /Views/Home/Index.cshtml, /Views/Shared/Index.cshtml, /Pages/Shared/Index.cshtml
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HMR6M20APD00", Request id "0HMR6M20APD00:00000001": An unhandled exception was thrown by the application.
      System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
      /Views/Home/Index.cshtml
      /Views/Shared/Index.cshtml
      /Pages/Shared/Index.cshtml
         at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
         at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
         at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
         at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.ExecuteWithFilterAsync(IHttpSocketAdapter injectScriptSocket, String requestId, HttpContext httpContext)
         at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Log do erro.

WebApp - Startup.cs

using Alura.LeilaoOnline.Core;
using Alura.LeilaoOnline.WebApp.Dados;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Alura.LeilaoOnline.WebApp
{
    public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration cfg)
        {
            Configuration = cfg;
        }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var cnxString = Configuration.GetConnectionString("LeiloesDB");
            services.AddDbContext<LeiloesContext>(options =>
            {
                options.UseSqlServer(cnxString);
            });
            services.AddTransient<IModalidadeAvaliacao, MaiorValor>();
            services.AddTransient<IRepositorio<Leilao>, RepositorioLeilao>();
            services.AddTransient<IRepositorio<Interessada>, RepositorioInteressada>();
            services.AddTransient<IRepositorio<Usuario>, RepositorioUsuario>();
            services.AddSession();
            services.AddMvc(options => options.EnableEndpointRouting = false);
        }

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

            app.UseStaticFiles();
            app.UseSession();

            app.UseMvcWithDefaultRoute();
        }
    }
}

Tentei mudar algumas coisas mas não conseguir fazer funcionar. Ele continua dando status 500.

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

solução!

Deletei o projeto e fiz novamente o download do projeto do professor. Mas agora eu instalei as SDKs que o proprio visual estudio recomendou e as migratios funcionaram perfeitamente.

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

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