Error using add-Migration command. Using json as configuration file

Asked

Viewed 121 times

1

Good morning!

When performing the add-Migration command, to make the migrations, I am receiving the error sequinte:

Add-Migration : Exception calling "AddFromFile" with "1" argument(s) : "'basePath' 
        não pode ser uma cadeia de caracteres vazia("") nem começar com o caractere nulo.
        Nome do parâmetro: basePath"At line:1 char:1
        + add-migration Initial
        + ~~~~~~~~~~~~~~~~~~~~~
         + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationE
            xception
            + FullyQualifiedErrorId : ArgumentException,Add-Migration

My context class

protected override void OnModelCreating(ModelBuilder modelBuilder)
    {

        ////////////////////////// MAPEAMENTOS ////////////////////////
        #region FluentAPI

        #region Barcos

        modelBuilder.Entity<Barco>()
           .ToTable("Barcos");

        modelBuilder.Entity<Barco>()
            .Property(e => e.Nome)
            .HasColumnType("varchar(150)")
            .IsRequired();

        modelBuilder.Entity<Barco>()
            .Property(e => e.CapacidadeAgua)
            .HasColumnType("varchar(50)")
            .IsRequired();

        modelBuilder.Entity<Barco>()
             .Property(e => e.CapacidadeOleo)
             .HasColumnType("varchar(50)")
             .IsRequired();

        modelBuilder.Entity<Barco>()
             .Property(e => e.SapId)
             .HasColumnType("varchar(10)")
             .IsRequired();

        modelBuilder.Entity<Barco>()
            .Ignore(b => b.ValidationResult);

        modelBuilder.Entity<Barco>()
            .Ignore(b => b.CascadeMode);

        modelBuilder.Entity<Barco>()
           .HasOne(b => b.CategoriaBarco)
           .WithMany(c => c.Barcos)
           .HasForeignKey(b => b.CategoriaBarcoID)
           .IsRequired();

        modelBuilder.Entity<Barco>()
            .HasOne(b => b.TipoOperacao)
            .WithMany(b => b.barcos)
            .HasForeignKey(b => b.TipoOperacaoID)
            .IsRequired();






        #endregion

        ////////////////////////// FIM MAPEAMENTO BARCOS////////////////////////

        #region CategoriaBarco

        modelBuilder.Entity<CategoriaBarco>()
           .ToTable("CategoriaBarco");

        modelBuilder.Entity<Barco>()
        .Ignore(b => b.ValidationResult);

        modelBuilder.Entity<Barco>()
            .Ignore(b => b.CascadeMode);


        #endregion


        #region TipoOperação

        modelBuilder.Entity<TipoOperacao>()
           .ToTable("TipoOperacao");

        modelBuilder.Entity<Barco>()
        .Ignore(b => b.ValidationResult);

        modelBuilder.Entity<Barco>()
            .Ignore(b => b.CascadeMode);



        #endregion

        #endregion


        base.OnModelCreating(modelBuilder);

    }


    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {

        var config = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json")
            .Build();

        optionsBuilder.UseOracle(config.GetConnectionString("DefaultConnection"));


    }





}

}

My json file:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=YOURSERVERNAME;   Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true"

},

 "Logging": {
   "IncludeScopes": false,
     "LogLevel": {
     Default": "Debug",
      "System": "Information",
         "Microsoft": "Information"
}

} }

Error says basepath is empty, but it is not I still don’t have the bank connections, because it will be online and have not passed the information, can that be the problem? I find it strange pq to do the Migrations, I think I do not need a bank (I think)

  • Managed to solve this problem?

1 answer

0

Check the structure of your project in Properties > App:

inserir a descrição da imagem aqui

Then check that this version is installed on your computer:

C:/Program Files/dotnet/Shared/Microsoft.NETCore.App

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.