Entity Framework Code First Migration Error

2020-02-24 12:26发布

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.

14条回答
够拽才男人
2楼-- · 2020-02-24 12:53

Tried all the things here. I personally hate solving things without knowing what the problem is in the first place. Digging down in forums this seems to be a known bug caused in version 6.3.0 when the startup project is a web app. They have already fixed it in their daily builds. So to solve it you need to install that.

First, uninstall the package:

PM> Uninstall-Package EntityFramework -Force

Then install the latest daily build (in my case the following one)

PM> Install-Package EntityFramework -Version 6.4.0-preview1-19506-01
查看更多
SAY GOODBYE
3楼-- · 2020-02-24 12:55

I was facing the same issue this is how I solved the issue,

I'm using Visual Studio 2019 and hence I installed latest Entity framework 6.3.0(stable) I was facing the issue when I run the Enable-Migrations command, I tried to re-install the Entity framework but it didn't work so I have installed the old version 6.2.0 from the Nuget package manger apparently it turned out working.

查看更多
登录 后发表回答