I'm new to MVC 4 and entity framework and when I run this command from the package manager console:
Enable-Migrations -ContextTypeName MyFirstMvcApp.Models.InventoryDbContext
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
I get the following error:
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:363 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 D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:392 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 D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:393 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 D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:426 char:19
+ (Join-Path <<<< $runner.ToolsPath EntityFramework.PowerShell.dll),
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
How do I fix this? Note that I am using Visual Studio 2010 Ultimate with SP1 and I have installed MVC4 in this link.
Shared with above suggestions here's my addition.
PM> Uninstall-Package EntityFramework -Force Then;
PM> Install-Package EntityFramework -Pre
this two above actions not enough. I needed to do the next one:
Then in the Solution Explorer, create a class with the below code inside your project at root level - in my case. and then Migrations folder with Configurations.cs file in it created automatically.
}
Some years later...
Another possible reason for this issue is the VS 2017 csproj format - or better said, the PackageReference approach in contrast to using packages.config.
With the new approach to include Nuget Packages using the PackageReference format in your project files, the install script of EntityFramework is not being executed (it is a known fact for this new approach of including nuget packages). Due to that fact, the PowerShell commands are not being ready for execution.
There is an ongoing discussion on that issue on the Entity Framework GitHub repository.
Until this is fixed (either by the NuGet people or the EF people) in order for migrations to run (talking of EF 6 - not EF Core!) you need to stick to the "old" way of including Nuget packages using the packages.config approach.
Check your Visual Studio settings at
Tools -> Options -> NuGet Package Manager -> General
and make sure that theDefault package management format
is set toPackages.config
.Note that you will have to uninstall all Packages, save the project, restart visual studio and afterwards re-install all packages when switching this setting.
In current Version of VS 2017 (I think from v 15.4 onwards) there is an automatic conversion from Packages.config to PackageReference, but not vice versa (unfortunately).
I was facing the same problem while working with Code First migrations.
What worked for me is go to NuGet packet manager, then search
Entity Framework
. There I had installed thePre-release version
, then I selected theLatest Stable version
and installed it.Everything worked perfectly afterwards.
I would like to add an additional thing that I found while having this issue.
As it turns out, in my case (Running Visual Studio 2017, Entity Framework 6.2) the issue was that the project was in a remote directory (\server\user\location) rather than a local directory.
Upon copying the project to a local location, the command runs without issue.
Fixed it by uninstalling and re-installing entity framework. For the benefit of others, here are the commands...
Uninstall:
After uninstalling, reinstall EntityFramework:
There! It's fixed. Though I still don't know what caused the problem.
i had the same problem when i updated EntityFramework to version 6.3.0 so when i went back to 6.2.0 it fixed the problem so i advice you to do the same