Cannot enable migrations in library project

c# entity-framework-6 nuget

Question

Within my library project, EF6 was installed. I inserted the connection string to a local database in the App.config file. I'm using EF code-based configuration for EF configuration: 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);
    }
}

My context class now has the property [DbConfigurationType(typeof(EFRecordConfiguration))].

Here is what happens when I run the command enable-migrations -Verbose:

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'.

I added the Migrations folder and Configuration.cs file to the project, but I still get this problem. The same problem occurs when I attempt to create a migration, however 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).

In the package management console, "MyProject.Example" is the default project chosen. The same (same setup) was attempted in a console project, and there was no issue.

Have I overlooked something in the EF configuration?

EDIT: I've discovered the source of the issue, which seems to be that assembly signing was active for my library project. What can I do to get the strong-named assembly to function with the EF migrations system?

1
0
7/22/2016 9:24:28 AM

Accepted Answer

ZZZ_tmp
0
5/23/2017 10:27:30 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow