Ef6: EF 6.3 Add-Migration not working

Created on 24 Sep 2019  路  7Comments  路  Source: dotnet/ef6

In our solution we have both EF and EF Core. EF is called only from full .NET projects and EF Core is called from a single .NET Core project.
Up until upgrading to EF 6.3 we added migrations trough PMC.
EntityFramework\add-migration -ConnectionStringName MyConnStringName -StartUpProjectName MyProject.Data -ProjectName MyProject.Data MIGRATIONNAME

After upgrade to EF 6.3 we get:

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///..........\packages\EntityFramework.6.3.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. The system cannot find the file specified."
At ..........\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:782 char:5
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-P ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

You cannot call a method on a null-valued expression.
At ..........\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:783 char:5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///..........\packages\EntityFramework.6.3.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. The system cannot find the file specified."
At ..........\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:811 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

App.Config of MyProject.Data:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  <section name="entityFramework"
    type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    requirePermission="false"/>
  </configSections>
  <connectionStrings>

      <add name="MyConnStringName" connectionString="Persist Security Info=True;Data Source=.;Initial Catalog=dev_db;Integrated Security=True"
        providerName="System.Data.SqlClient"/>

  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.3.0.0"/>
      </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
        </dependentAssembly>
    </assemblyBinding>
  </runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>

I read that there is new ef6.exe instead of migrate.exe but I can't find anything about how to use it.

Further technical details

EF version: 6.3
Database Provider: EntityFramework.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2019 16.3.0 Preview 4.0

closed-question

Most helpful comment

The PowerShell module name has changed to EntityFramework6:

EntityFramework6\Add-Migration ...

All 7 comments

After upgrading to 16.4.0 Preview 1 I get following message for same command in PMC

EntityFramework\add-migration : The module 'EntityFramework' could not be loaded. For more information, run 'Import-Module EntityFramework'.
At line:1 char:1
+ EntityFramework\add-migration -ConnectionStringName PayEntities -Star ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (EntityFramework\add-migration:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule

and running Import-Module EntityFramework results in

Import-Module : The specified module 'EntityFramework' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module EntityFramework
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (EntityFramework:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

The PowerShell module name has changed to EntityFramework6:

EntityFramework6\Add-Migration ...

This resolved the issue. Thanks

Is that documented anywhere? I searched but didn't find anything

馃槄 Not documented; I didn't think it would actually break anyone...

Were also experiencing difficulty with migrations in PMC after upgrading to 6.3. We were previously on 6.2 in a solution that primary has .Net Framework 4.6.1 projects (including our data project).

Our issue is slightly different in that we are getting a cmdlet cannot be found error (including when trying EntityFramework6\Add-Migration. Interestingly, "Get-Help Add-Migration" will return the help page for EntityFramework6 and not the page for Add-Migration.

At the end of the day we had to revert back to EF 6.2 and then were able to get our migrations in.

I have the same issue than @merccat with a .Net 4.6.2 project. I also had to rollback to EF 6.2

You only need to install Microsoft.EntityFrameworkCore.Tools
Verify the version than can be support for your project

Was this page helpful?
0 / 5 - 0 ratings