26

我是 MVC 4 和实体框架的新手,当我从包管理器控制台运行此命令时:

Enable-Migrations -ContextTypeName MyFirstMvcApp.Models.InventoryDbContext

加入路径:无法将参数绑定到参数“路径”,因为它为空。

我收到以下错误:

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

我该如何解决?请注意,我使用的是带有 SP1 的 Visual Studio 2010 Ultimate,并且我已在此链接中安装了 MVC4 。

4

14 回答 14

41

通过卸载并重新安装实体框架来修复它。为了他人的利益,这里是命令...

卸载:

PM> 卸载-打包EntityFramework -Force

卸载后重新安装EntityFramework:

PM> Install-Package EntityFramework -Pre

那里!它是固定的。虽然我仍然不知道是什么导致了问题。

于 2013-01-22T03:37:47.197 回答
22

Visual studio 2019: Uninstall-Package EntityFramework -Force

then

Install-Package EntityFramework -Pre -Version 6.2.0

something is up with v6.3.0

于 2019-10-02T19:00:39.240 回答
13

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.

于 2019-09-28T18:46:27.623 回答
13

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
于 2019-10-25T08:06:38.717 回答
5

I came across this issue while upgrading to EntityFramework "6.3.0" from "6.2.0". The issue and workaround can be found here EF 6.3.0 PMC commands throw ParameterBindingValidationException when Startup Project is a Web App.

The problem arises when you have multiple projects and you set an ASP.NET project as the Startup project

Workaround suggested by the link:

If you added a new dummy console app to the solution and installed the daily build of the EntityFramework into it, that version of the commands which includes the fix would be used. The commands would work just fine with projects referencing EF 6.3.

Personal Solution:

Setting the Startup project to a non ASP.NET project fixed the issue in my case. Note that you will have to copy the connection strings to the relevant project's configuration file if you're using them.

于 2019-10-10T04:18:09.760 回答
4

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 the
Default package management format is set to Packages.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).

于 2018-08-15T06:01:08.983 回答
4

I had the same problem and solved it by changing the Startup Project.

I have 5 project in the same solution and each time I Right Click and Set as startup to a non ASPNET CORE project, I get this kind of error.

于 2018-10-19T12:50:00.797 回答
3

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

于 2019-10-05T15:03:00.693 回答
2

卸载实体框架对我不起作用。

It turned out that it was not Visual Studio or Entity Framemwork casuing the problem, but it was the fact I was running PowerShell 2 (on Windows 7).

Entity Framework and Visual Studio require PowerShell 3.

Following the update and reboot, the issue was gone. Hopefully this will help a few people.

You can find PowerShell here -> https://www.microsoft.com/en-us/download/details.aspx?id=40855

于 2015-06-22T13:55:49.420 回答
1

In my case none of the above solutions worked, so I had a quick look in the packages.config file and to my surprise found two entries for Entity Framework

<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />

Note that they are different versions, not sure how this could actually happen. Anyway, once I removed the older one from the packages.config file i.e. ended up with just this one:

<package id="EntityFramework" version="6.1.3" targetFramework="net45" />

I could then Enable-Migrations with no issues.

于 2015-11-23T11:45:50.607 回答
1

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 the Pre-release version, then I selected the Latest Stable version and installed it.

Everything worked perfectly afterwards.

于 2019-09-07T22:14:19.947 回答
1

As of version 6.3, the Entity Framework tooling supports the new SDK-style project format.

However, this issue can still happen when the project containing your migrations uses the new SDK-style format, while the startup project is using the classic csproj format.

To fix this, make both projects use the same csproj format.

于 2019-09-28T20:17:31.040 回答
0

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.

public class MyDbContext : DbContext
{
pubic MyDbContext()
{
}

}

于 2019-11-14T17:28:13.560 回答
0

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.

于 2019-11-22T11:30:03.507 回答