Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on Enable-Migrations

I'm new with EF and I have an error when I try to run Enable-Migrations in PMC console : Exception calling "LoadFrom" with "1" argument(s):

 "Could not load file or assembly 'file:///...\pa
ckages\EntityFramework.6.0.1\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:780 char: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 ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:781 char: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:///...\packages\EntityFramework.6.0.1\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is no t supported. (Exception from HRESULT: 0x80131515)"
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:809 char:31
+     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
like image 836
user3933462 Avatar asked Aug 12 '14 13:08

user3933462


People also ask

How do I enable migrations in Visual Studio?

From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.

What is migrations in C#?

The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

How to enable migration in Visual Studio 2010?

Go to Package Manager Console and type command help migration. Type Enable-Migrations -ContextTypeName EXPShopContext. This command creates a migration folder with InitialCreate.cs and Configuration.cs file, where all the code is written for updating. We can see Solution Explorer, given below:

How do I fix the migration error when building a program?

Removing the Configuration class solved my problem. This can also happen if you are building a 64-bit application. Switch to "Any CPU", at least temporarily while building the migrations, and the problem may go away. This is just one thing that can cause that error, though.

Why can’t I generate an explicit migration?

Unable to generate an explicit migration because the following explicit migrations are pending: [20161081751088_InitialCreate, 20161091825212_ClientID]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

How do I add a migration to a database?

(To create an empty migration and solve the errors that you are facing.) Run the Update-Database command to apply your empty migration. Make changes to your code first model for preparing to adding your real migration. Run the Add-Migration InitNew command to create a new migration. Run the Update-Database command to apply the changes.


1 Answers

I just ran into this on one of my co-worker's machine. The solution was:

  1. Uninstall EF NuGet package
  2. Manually remove Entity Framework sections from the Web.Config/App.Config files
  3. Close Visual Studio
  4. Re-open the solution in Visual Studio
  5. Reinstall the EF NuGet Package
like image 111
DVK Avatar answered Sep 27 '22 20:09

DVK