11
votes

I'm using Entity framework 4.3.1 installed by nuget in my .Net 4.0 class library project. In situation, when I call the "Enable-Migrations" command in PM console, I receive following exception:

Exception calling "LoadFrom" with "1" argument(s): "Nelze načíst soubor nebo sestavení file:///D:\ Users\DvoracekR\Documents\Visual Studio 2010\Projects\WebCameras\packages\EntityFramework.4.3.1\to ols\EntityFramework.PowerShell.Utility.dll nebo jeden z jejich závislých prvků. Systém nemůže nalé zt uvedený soubor." At D:\Users\DvoracekR\Documents\Visual Studio 2010\Projects\WebCameras\packages\EntityFramework.5. 0.0-rc\tools\EntityFramework.psm1:393 char:62 + $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $toolsPath Entity Framework.PowerShell.Utility.dll)) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression. At D:\Users\DvoracekR\Documents\Visual Studio 2010\Projects\WebCameras\packages\EntityFramework.5. 0.0-rc\tools\EntityFramework.psm1:394 char:50 + $dispatcher = $utilityAssembly.CreateInstance <<<< ( + CategoryInfo : InvalidOperation: (CreateInstance:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Typ System.Data.Entity.Migrations.En ableMigrationsCommand ze sestavení EntityFramework.PowerShell, Version=4.3.1.0, Culture=neutral, P ublicKeyToken=b77a5c561934e089 nelze načíst." At D:\Users\DvoracekR\Documents\Visual Studio 2010\Projects\WebCameras\packages\EntityFramework.5. 0.0-rc\tools\EntityFramework.psm1:418 char:31>+ $domain.CreateInstanceFrom <<<< ( + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

6
If you want to get answer here avoid localized versions of .NET framework - questions with information in local language are usually closed as too localized. Your error message contains some contradicting information - it tries to load EF 4.3.1 PowerShell extension from EF 5.0 RC directory. So what version are you using?Ladislav Mrnka
I'm using version 4.3.1. I also tried to uninstall Entity Framework using NuGet and install it again. Nothing changed. Enable-Migrations command is still trying load non existing assembly. Should I try to install latest pre-release version?Rudolf Dvoracek
What do you see in packages.config and in Packages directory?Ladislav Mrnka
packages.config file: <?xml version="1.0" encoding="utf-8"?> <packages> <package id="EntityFramework" version="4.3.1" /> <package id="Lextm.SharpSnmpLib" version="7.0.0.2" /> <package id="log4net" version="2.0.0" /> </packages>Rudolf Dvoracek
I have only these subdirectories in my packages directory 13.06.2012 09:33 <DIR> . 13.06.2012 09:33 <DIR> .. 18.05.2012 12:16 <DIR> Common.Logging.2.0.0 13.06.2012 09:33 <DIR> EntityFramework.4.3.1 20.01.2012 09:33 <DIR> Lextm.SharpSnmpLib.7.0 10.05.2012 15:41 <DIR> Lextm.SharpSnmpLib.7.0.0.2 18.05.2012 12:03 <DIR> log4net.2.0.0 26.03.2012 13:55 <DIR> MvvmLight.3.1.1 12.06.2012 16:54 437 repositories.config 12.04.2012 11:14 <DIR> SilverlightToolkitWP.4.2011.12.14Rudolf Dvoracek

6 Answers

25
votes

I solved problem described above.

  1. I uninstalled Entity framework using NuGet package manager.
  2. I manually cleared subdirectories started with "Entity" in packages directory.
  3. I installed Entity Framework 4.3.1 again

Now migrations are enabled correctly.

2
votes

I know this is an old question and already has an accepted answer, but I had this issue and thought I'd share what I did to resolve it.


My solution was in source control and I had messed up my local project. I decided to start over from Source Control, so I created a new folder and Checked out the code from SVN.

When I did, I was no longer able to create migrations. I got the same error listed above. I tried Uninstall-Package EntityFramework, but got a similar message about missing files/references within EntityFramework.

I went back to my old folder and looked in $Project\packages\EntityFramework.6.0.2\ and compared this to my new folder. There were several DLLs/Xml files missing because they were not in Source Control. They were in the \tools\ , \lib\net40 and \lib\net45\ directories.

I just copied these files to my new project, closed/reopened Visual Studio, and did a Rebuild. After that, everything was working fine.

1
votes

Reinstalling the NuGet package didn't work for me. What did work was to move the project from a network drive to a local drive. Running a compare showed that, apart from obj and bin directories, all files were binary identical.

If I remember correctly, my last attempt at Update-Database was before I moved the project to a network drive.

0
votes

I experiencing this problem when sharing a project with a college by sending him the project. When he sent it back to me I discovered the returned project gave me this error when I tried to add a migration. I solved the problem by over-writing the packages\EntityFramework.5.0.0 folder from the returned project with the folder from my original project.

I don't get the problem if I just move the project about on my own machine.

0
votes

This problem started happening to me when using different VM's on the same physical machine.

VMWare Fusion defaults to share the profiles directory with OS X, which in turn creates a lot of problems when using multiple VMs with Visual Studio installed, actually almost every application I had installed begun to behave strangely. Should have rung a bell at that time.

The problem was resolved by turning off Folder Sharing, which is not so obvious since I hadn't the option to not share the profile folder, only add/remove other folders.

Hope my stupidity helped someone else out there :)

0
votes

I have the same problem with projects from Visual Studio 2015 that was open on Visual Studio 2017. Here's how I solved it:

  1. Manually remove Entity Framework from Tools -> NuGet Package Manager -> Manage NuGet Packages From Solution
  2. Search for Entity Framework.
  3. Unfortunately, there are dependencies. So forcing to remove only Entity Framework doesn't solve the problem at all. So whatever the dependencies are, manually remove it from the steps above.
  4. Lastly install again Entity Framework and whatever dependencies that you might have removed. Upon completing this, I didn't restart my Visual Studio, upon typing enable-migrations, everything worked fine already.

To share my experience as well, I tried this step:

Uninstall-Package EntityFramework -Force

Then install it for each project:

Install-Package EntityFramework

But didn't worked on my part. So I guessed I had to manually uninstall it including its dependencies without using force and install it again to work. But glad it did.