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
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.
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.
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:
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.
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.
(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.
I just ran into this on one of my co-worker's machine. The solution was:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With