简体   繁体   中英

Entity Framework Import-Module : The specified module '…EntityFramework.psd1' was not loaded

Recently I decided to use Entity Framework for a personal project. From my Visual Studio 2013 community edition and using NuGet I installed the latest version of the framework (nuget version 2.8.60318.734 and Entity Framework 6.1.3)

Everything seems to work OK I was able to perform simple CRUD operations, till I needed to update my model. After it, of course I got the error message:

“Additional information: The model backing the 'MyContext' context has changed since 
the database was created. Consider using Code First Migrations to update the database 
(http://go.microsoft.com/fwlink/?LinkId=238269).”

Seems an appropriate error message, I just need to Enable-Migrations. Switch to Package Manager Console and there was a message in bright red background

PM> Import-Module : The specified module 'D:\[MyProjects]\[ProfOfConcept]\EntityFrameworkInvalidFilepath\packages\EntityFramework.6.1.3\tools\EntityFramework.psd1' was not loaded because
 no valid module file was found in any module directory.
At D:\[MyProjects]\[ProfOfConcept]\EntityFrameworkInvalidFilepath\packages\EntityFramework.6.1.3\tools\init.ps1:8 char:14
+ Import-Module <<<<  (Join-Path $toolsPath EntityFramework.psd1)
    + CategoryInfo          : ResourceUnavailable: (D:\[MyProjects]...yFramework.psd1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Hmmmm something is wrong, I guess some needed part of the framework was not correctly installed, but let's check the file. The file was present, and the content seemed OK.

Alright let's try to reinstall it, just in case something went wrong at the first time. Using NuGet I tried to uninstall, and reinstall.

Checking Package Manager Console, again the same dreaded error!

Hmmm, let's try to do the uninstall /reinstall from the Package Manager Console. Again the same error!

After spending more time trying to Google similar problems I came across someone describing a similar problem Entity Framework with NuGet - Import-Module error in init.ps1 Tried that… no luck.

So what is really going on? In a Eureka moment I thought… hold on, what was my project path?

D:\[MyProjects]\[ProofOfConcept]\….

Could it be? Could the square brackets be the reason?

Create a copy the project to a simple path (d:\\tmp\\myProject) start the Visual Studio, enter Package Management Console, …. no error !

Enable-Migrations
PM> Enable-Migrations
Checking if the context targets an existing database...
Detected database created with a database initializer. Scaffolded migration '201504051040353_InitialCreate' corresponding to existing database. To use an automatic migration instead, delete the Migrations folder and re-run Enable-Migrations specifying the -EnableAutomaticMigrations parameter.
Code First Migrations enabled for project EntityFrameworkInvalidFilepath.

That's it!! The square brackets are the culprits

So the bottom line is this, if you are using Entity Framework don't use [ ] in the path.

I recently had the same issue with NuGet not installing EF 6.1.3 properly because the EntityFramework.psd1 file wasn't being imported. Uninstalling and re-installing EF through Visual Studio didn't help.

What worked for me was to quit VS, navigate to '[Project Root Directory]\\packages' and delete the EntityFramework6.1.3 directory. When you restart VS and go to the package manager console, it will let you know that there are modules missing and ask if you want to import them. When you click 'Reload' EF 6.1.3 is installed properly under the 'packages' directory.

In my case I'm using the 2015RC, which has a lot of issues with EF migrations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM