Entitiy Framework migration with EF in multiple projects

1.3k views Asked by At

Currently I trying to separate my data model into a different project in the same solution, with code first. If I only have one project with EF( 6.1.3 ) installed, migration ( Enable-Migration, Add-Migration ) work as intended.

But as I add an other project and install EF packet, if i try Enable-Migration, I've got this error:

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:713 char:27
+     $toolsPath = Join-Path <<<<  $installPath tools
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:73
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path <<<<  $ToolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

You cannot call a method on a null-valued expression.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:810 char:19
+         (Join-Path <<<<  $runner.ToolsPath EntityFramework.PowerShell.dll),
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

EF seems to work fine in both of the projects. Reinstalling EF to either or both of the projects did not solve it. Any solution in mind?

EDIT: I started a new solution with 3 projects, 1. for the basecontext( public class BaseContext<TContext> : DbContext where TContext : DbContext ... ), 2. for base classes, and 3. for creating a context based on base context and the classes. If i put ef in only one then migrtation works, or at least tells me thet it can't find a context, but if i install it into more then one, then it's producing the error again.

2

There are 2 answers

1
Leandro de Castro Silva On

I found the same problem today and I had to uninstall the EF and install again.

PM> Uninstall-Package EntityFramework -Force

PM> Install-Package EntityFramework -Pre

0
MrKekson On

Ok, solved it, the problem was not EF, or VS2015, but my Windows 7, since it come with PowerShell 2, but EF or VS required PowerShell 3 to work properly. After updating to it the errors was gone.

Then i run ito this bug: https://connect.microsoft.com/VisualStudio/feedback/details/1302181/add-migration-bug what is currently under review.

It seems like that it's caused by some configuration bug in the VS2015 RC release. Rolled back to VS13 with powershell 2, reinstalled the related nuget packages, and it's working fine now.