2
respostas

Não consigo executar o comando Add-Migration criaUsuario

Fiz todos os procedimentos conforme explicado no curso criei todas as classes e instalei os pacotes com as versoes 7 rc1 final porem recebo esse erro ao add-migration

PM> Add-Migration criaUsuario System.ArgumentNullException: Value cannot be null. Parameter name: configuration.ContextType at System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.<>cDisplayClass2.<.ctor>b0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Value cannot be null. Parameter name: configuration.ContextType

2 respostas

Oi Lais!

A equipe do Entity Framework da Microsoft está ciente desse erro:

https://github.com/aspnet/EntityFramework/issues/5657

Pelo jeito, eles corrigiram no RC2. Você pode instalar o RC2 e ver se o problema foi resolvido?

https://docs.microsoft.com/en-us/ef/core/miscellaneous/rc1-rc2-upgrade

Obrigado!

Removi os pacotes de versoes anteriores e instalei os novos conforme a documentação "Upgrading from RC1 to RC2" e alterei o using para "using Microsoft.EntityFrameworkCore;", porém o erro agora é outro:

PM> Add-Migration CriaUsuario System.Reflection.TargetInvocationException: Uma exce‡Æo foi acionada pelo destino de uma chamada. ---> System.IO.FileLoadException: NÆo foi poss¡vel carregar arquivo ou assembly 'System.Interactive.Async, Version=3.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' ou uma de suas dependˆncias. A defini‡Æo do manifesto do assembly localizado nÆo corresponde … referˆncia do assembly. (Exce‡Æo de HRESULT: 0x80131040) em Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.AddQuery(IServiceCollection serviceCollection) em Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.AddEntityFramework(IServiceCollection serviceCollection) em Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>cDisplayClass4_1.b2(Int64 k) em System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) em Microsoft.EntityFrameworkCore.DbContext.GetServiceProvider(DbContextOptions options) em Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)

em EntityFramework.EntidadesContext..ctor()

Fim do rastreamento de pilha de exce‡äes internas --- em System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) em System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) em System.Activator.CreateInstance(Type type, Boolean nonPublic) em System.Activator.CreateInstance(Type type) em Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>cDisplayClass12_3.b13() em Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory) em Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) em Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) em Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) em Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_01.b__0() em Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Uma exce‡Æo foi acionada pelo destino de uma chamada.

Segue minha classe EntidadesContext:

public class EntidadesContext : DbContext { public DbSet Usuarios { get; set; } public DbSet Categorias { get; set; } public DbSet Produtos { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string stringConexao = ConfigurationManager.ConnectionStrings["lojaConnectionString"].ConnectionString; optionsBuilder.UseSqlServer(stringConexao); base.OnConfiguring(optionsBuilder); } }