23

I have several class files. Now I am adding a new model class and tried to type add-migration InitialCreate but am getting the following error:

PM> add-migration InitialCreate
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\user\Documents\Visual Studio 2013\Pro
jects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operati
on is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 c
har:62
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 c
har:50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///C:\Users\user\Documents\Visual Studi
o 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Opera
tion is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:809 c
har:31
+     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

PM>
Itchydon
  • 2,572
  • 6
  • 19
  • 33
noushad mohammed
  • 375
  • 1
  • 4
  • 20

9 Answers9

25

Using the Package Manager, you need to re-install Entity Framework:

Uninstall-Package EntityFramework -Force

Then install it for each project:

Install-Package EntityFramework

Then do not forget to restart the studio.

https://stackoverflow.com/a/14994432/1845408

Community
  • 1
  • 1
renakre
  • 8,001
  • 5
  • 46
  • 99
11

Used the command EntityFramework6\add-migration {migration name} instead. Microsoft changed the name of the command.

  • Your answer is very useful. It seems at first try using add-migration alone, it works after apply _"enable-migrations"_ commmand. I tried without "EntityFramework" switch and appears the @noushad-mohammed error. I'm using: **VS2019 CE** **EF 6.4.4** Now I understand why appears the follow message every time I started "enable-migrations" `A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Add-Migration' for the older version.` Thanks. – Hagen Aug 13 '20 at 15:49
6

Just restart the visual studio and clean the solution and rebuild it again.

Fahad
  • 91
  • 1
  • 3
3

Make sure that VS in admin mode

3

In my case, it was a different entity-framework version between main project and the project containing DbContext. I just updated version of package in both projects to v6.4.4

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
2

I had a slightly different case today, I'm wirting the details here in case that might help somebody. The error was referencing one of my assemblies instead, on which the assembly containing the EF DbContext was depending.
I solved it setting the referenced assembly to "Copy Local" "true" so it'd make a local copy when building for migrations and therefore be able to find it.

baywet
  • 4,377
  • 4
  • 20
  • 49
2

you need to re-install Entity Framework:

Anusha B
  • 91
  • 1
  • 10
1

I went to "Manage Nuget Packages for Solution..." and updated all my packages. This worked for me.

Then I got another error Cannot bind argument to parameter 'Path' because it is null.

Setting another project as startup project other then my web app, before running any EF command in Package Manager Console, worked for me.

Mari Faleiros
  • 898
  • 9
  • 24
  • Yes, this error was resolved after "Setting another project as startup project other then my web app". Thank you – user1947393 Jul 08 '21 at 06:32
0

Whats missing are the dlls from (Solution Folder)/packages/EntityFramework.6.1.3/tools/.

Things I would try:

  1. Nuget will keep a copy of the .nupkg you might find the missing files there ((Solution Folder)/packages/EntityFramework.X.Y.Z/) (Open the nupkg as zip)
  2. If not you may have luck redownloading the package manually here https://www.nuget.org/packages/EntityFramework (Make sure you download the right packages. In your case it would be 6.1.3)

If that doesnt work you can retry one of the above solutions of completely removing and reinstalling EF but make sure you install the same version for each project.

Also there seem to be versions that dont include those files. For example as of writing this answer 6.3.0 actually doesnt include the dlls needed while 6.1.3 does. I also had success copying the dlls from an older version like 6.1.3 into the newer like 6.3.1 (Might give a warning but generally works as expected).

Lukas Willin
  • 345
  • 3
  • 9