Errors in Net Core Add-Migration

Visual Studio 2017 version 15.5.2, Net Core 2.

Add-Migration error:

Exception calling "SetData" with "2" argument(s): "Type 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in 
assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=15.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\wanj\.nuget\packages\entityframework\6.2.0\tools\EntityFramework.psm1:720 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException

Exception calling "SetData" with "2" argument(s): "Type 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in 
assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=15.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\wanj\.nuget\packages\entityframework\6.2.0\tools\EntityFramework.psm1:721 char:5
+     $domain.SetData('contextProject', $contextProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException

Solution:
Check all the following three required NuGet packages are installed, https://developercommunity.visualstudio.com/content/problem/69983/enabling-ef-migrations-fails-with-error.html:
  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Tools
  • Microsoft.EntityFrameworkCore.SqlServer
  1. Remove previously installed EntityFramework (v6.2.0) and install Microsoft.EntityFrameworkCore instead.
  2.  Update all  to the newest versions

Run EntityFrameworkCore\Add-Migration again, the above error is gone, but a new error showed up:

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

Solution:
Add-Migration MyMigrationName -context LibProgramContext

See https://stackoverflow.com/questions/38162227/asp-net-core-ef-add-migration-command-not-working

Comments

Post a Comment

Popular posts from this blog

Use GnuPG Tools or C# Code for PGP Encryption and Signature

Confusing Concepts about SFTP: SSH2 vs OpenSSH