问题
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
回答1:
I solved problem described above.
- I uninstalled Entity framework using NuGet package manager.
- I manually cleared subdirectories started with "Entity" in packages directory.
- I installed Entity Framework 4.3.1 again
Now migrations are enabled correctly.
回答2:
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.
回答3:
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.
回答4:
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.
回答5:
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 :)
回答6:
I have the same problem with projects from Visual Studio 2015 that was open on Visual Studio 2017. Here's how I solved it:
- Manually remove Entity Framework from Tools -> NuGet Package Manager -> Manage NuGet Packages From Solution
- Search for Entity Framework.
- 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.
- 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.
来源:https://stackoverflow.com/questions/10999561/exception-raised-when-im-trying-enable-migrations-in-ef-4-3-1