Ef6: cannot bind argument to parameter 'path' because it is null

Created on 14 Mar 2018  路  22Comments  路  Source: dotnet/ef6

Using latest EF and VS2017 (with all latest updates).
When I execute any migration command, e.g:

Add-Migration InitialMigration

I'm getting the following error:

Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration' for Entity Framework 6.
Unable to resolve startup project ''.
Add-Migration : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:1

  • Add-Migration InitialMigration
  • ~~~~~~

    • CategoryInfo : InvalidData: (:) [Add-Migration], ParameterBindingValidationException

    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-Migration

closed-fixed

Most helpful comment

I realize that this issue is closed but I too have started seeing this issue and thought this might be helpful still.

Here's my solution set up:

  • .NET Framework 4.7.2 Web App (here called Project)
  • I have placed my Models, Migrations, and DbContext in a separate project Project.Data

My repro steps are:

  1. Start by using EF 6.2.0
  2. Update-Package EntityFramework to use 6.3.0
  3. Run Add-Migration ANewMigration
  4. Receive:
Add-Migration : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:1
+ Add-Migration -StartUpProjectName Pegasus -ProjectName Pegasus.Data - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Migration], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-Migration

I debugged the NuGet package locally and found that this was consistently happening on each of the PMC commands.

Furthermore, I found that this ParameterBindingValidationException is happening here:

    if (IsWeb $startupProject)
    {
        $params += '--data-dir', (Join-Path $startupProjectDir 'App_Data')
    }

on line 918 of src/NuGet/EntityFramework/tools/EntityFramework6.psm1

I noticed that $startupProjectDir is the path for Join-Path but it is not defined at any place in the PMC for that version.

Locally, I was able to resolve this by updating these lines like this:

    if (IsWeb $startupProject)
    {                
        $startupProjectDir = GetProperty $startupProject.Properties 'FullPath'        
        $params += '--data-dir', (Join-Path $startupProjectDir 'App_Data')
    }

This allowed me to use the PMC from an external project. I hope this helps!

P.S. I started a new .NET Framework 4.7.2 web app, with Models and DbContext in the same project and installed EF 6.3.0 right off and still received the same error.

I'd be happy to submit a PR for this if you guys are up for it. Just let me know!

All 22 comments

EF Team Triage: This issue is lacking enough information for us to be able to effectively triage it. In particular, it is missing the following information requested in the new issue template. Can you please provide this information?

Steps to reproduce

Ideally include a complete code listing that we can run to reproduce the issue.
Alternatively, you can provide a project/solution that we can run.

BTW we're not just doing this to be mean :smile:... we get a lot traffic on this project and it takes time to attempt to reproduce an issue based on fragments of information. In addition, our attempt is often unsuccessful as the exact conditions required to hit the issue are often not explicitly included in the code provided. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we ask that folks give us a self-contained way to reproduce an issue.

For a guide on submitting good bug reports, read Painless Bug Tracking.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

I realize that this issue is closed but I too have started seeing this issue and thought this might be helpful still.

Here's my solution set up:

  • .NET Framework 4.7.2 Web App (here called Project)
  • I have placed my Models, Migrations, and DbContext in a separate project Project.Data

My repro steps are:

  1. Start by using EF 6.2.0
  2. Update-Package EntityFramework to use 6.3.0
  3. Run Add-Migration ANewMigration
  4. Receive:
Add-Migration : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:1
+ Add-Migration -StartUpProjectName Pegasus -ProjectName Pegasus.Data - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Migration], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-Migration

I debugged the NuGet package locally and found that this was consistently happening on each of the PMC commands.

Furthermore, I found that this ParameterBindingValidationException is happening here:

    if (IsWeb $startupProject)
    {
        $params += '--data-dir', (Join-Path $startupProjectDir 'App_Data')
    }

on line 918 of src/NuGet/EntityFramework/tools/EntityFramework6.psm1

I noticed that $startupProjectDir is the path for Join-Path but it is not defined at any place in the PMC for that version.

Locally, I was able to resolve this by updating these lines like this:

    if (IsWeb $startupProject)
    {                
        $startupProjectDir = GetProperty $startupProject.Properties 'FullPath'        
        $params += '--data-dir', (Join-Path $startupProjectDir 'App_Data')
    }

This allowed me to use the PMC from an external project. I hope this helps!

P.S. I started a new .NET Framework 4.7.2 web app, with Models and DbContext in the same project and installed EF 6.3.0 right off and still received the same error.

I'd be happy to submit a PR for this if you guys are up for it. Just let me know!

I just wanted to add that I've hit the same issue as @Psypher9, and his proposed fix solved it. I'd upgraded the NuGet packages to 6.3 (I'm using Framework 4.6.2, VS2019) and the powershell commands stopped working. In my case the startup project was a Web application. Making the proposed change to [solution]/packages/EntityFramework.6.3.0/tools/EntityFramework6.psm1 and then restarting visual studio seems to have fixed the problem.

Same here, can be fixed with workaround from @Psypher9

same here, fixed with the workaround from @Psypher9

also fixed with the workaround from @Psypher9, thanks for the workaround until something permanent comes along!

@Psypher9 would you be willing to open a new issue for better visibility to others who have the same issue as well as devs on the MS team like @ajcvickers. If not I will, but since you did all the leg work you should be the one who has their name on the issue.

@fetters5 sure I can do that. Thanks for suggesting it!

Same issue. Resolved with workaround. Thanks a lot, @Psypher9 .

FYI, @Psypher9's fix is included in our daily builds (see link for setup instructions). Feel free to start using it today via the version 6.4.0-preview1-* prerelease packages.

Awesome Fix! @Psypher9

I'm still getting this error when i try to execute the Enable-Migration Command i have a web app in net framework 4.7.2 and ef 6.3

I had the same problems.
I created a new project and tested each version, the bug happened in preview version 8 and continues until the final version

I get it fixed by setting the project containing DbContext as the Startup Project

Try downgrading to EF 6.2.0.

I had the same problem, but it's gone now.

I use .Net Framework 4.7.2 with EF 6.2.0.

framework 4.7.2 and EF 6.2.0 works fine, but the 6.3 version shows the same error ("...Cannot bind argument to parameter 'Path' because it is null...") when I execute "Enable-Migrations"

Same issue and awesome fix. Thanks @Psypher9

Thanks, @Psypher9. Works for me.

FYI, @Psypher9's fix is included in our daily builds (see link for setup instructions). Feel free to start using it today via the version 6.4.0-preview1-* prerelease packages.

I don't suppose you could ship a 6.3.1 release with this fix? Not great for something basic like adding a migration to not work out-of-the-box, and I'm not inclined to use a prerelease just for a tooling fix.

@dahlbyk The fix is in 6.4, which will be released December 3.

@raza707mirza You saved my life haha

Was this page helpful?
0 / 5 - 0 ratings