I installed EF6 in my library project. In the App.config, i added the connection string to a local DB. For EF configuration, i am using EF code based config : App.config:
<entityFramework codeConfigurationType="Com.EF.Example.EFRecordConfiguration, MyProject.Example">
</entityFramework>
EFRecordConfiguration.cs :
public class EFRecordConfiguration : DbConfiguration
{
public EFRecordConfiguration()
{
SetDefaultConnectionFactory(new System.Data.Entity.Infrastructure.SqlConnectionFactory());
SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
}
}
I added the attribute [DbConfigurationType(typeof(EFRecordConfiguration))] to my context class.
When i use the command enable-migrations -Verbose, here is the result :
PM> enable-migrations -Verbose
Using StartUp project 'MyProject.Example'.
Using NuGet project 'MyProject.Example'.
Checking if the context targets an existing database...
System.Data.Entity.Migrations.Infrastructure.MigrationsException: The migrations configuration type 'Com.EF.Example.Migrations.Configuration' was not be found in the assembly 'MyProject.Example'.
à System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType, String typeName, Func`2 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
à System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrat ionsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
à System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
à System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
à System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
à System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
à System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
à System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(String language, String rootNamespace)
à System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
à System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The migrations configuration type 'Com.EF.Example.Migrations.Configuration' was not be found in the assembly 'MyProject.Example'.
The folder Migrations and the file Configuration.cs is added in the project, however, i get this error. When i try to add a migration, same error, but the migration file is not added :
PM> add-migration InitialCreate -Verbose
Using StartUp project 'MyProject.Example'.
Using NuGet project 'MyProject.Example'.
System.Data.Entity.Migrations.Infrastructure.MigrationsException: No migrations configuration type was found in the assembly 'MyProject.Example'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
à System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType, String typeName, Func`2 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
à System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
à System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration( )
à System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
à System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
à System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
à System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
à System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
à System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
à System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
à System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
No migrations configuration type was found in the assembly 'MyProject.Example'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
The default project selected is 'MyProject.Example' in the package manager console. I tried to do the same (same configuration) in a console project, no error.
Is there anything i forgot in EF configuration ?
EDIT: I found what is the problem : I activated assembly signing for my library project, and it seems to be the problem. What can I do to make the EF migrations system works with strong-named assembly ?
I found a workaround : EntityFramework CodeFirst migrations in dll with strong name
However, how to avoid to add assembly in GAC, restart VS and then add migration ?
EDIT: it is not possible.