Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception raised when I'm trying enable migrations in EF 4.3.1

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

like image 685
Rudolf Dvoracek Avatar asked Jun 12 '12 15:06

Rudolf Dvoracek


3 Answers

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.

like image 150
Rudolf Dvoracek Avatar answered Nov 08 '22 14:11

Rudolf Dvoracek


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.

like image 35
L_7337 Avatar answered Nov 08 '22 13:11

L_7337


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.

like image 43
user247702 Avatar answered Nov 08 '22 13:11

user247702