Cannot enable migrations in VS.2017 with ASP.NET Core web application entity-framework-6


I started to build my ASP.NET web application with the ASP.NET Core template. I noticed it has already two files in the ~\Data\Migrations folder one naemd *_CreateIdentitySchema.cs and the other ApplicationDbContextModelSnapshot.

At first it was complaining that i had Powershell 2 so I installed v3. Then I installed the package EntityFramework (v6.1.3) from the package manager because somehow that was not installed from the template as it was the case in VS.2015.

Now it gives me an error like "Exception calling "SetData" with "2" argument(s): " and then a bunch of things.

 $domain.SetData('contextProject', $contextProject)
 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=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\Devel.nuget\packages\entityframework\6.1.3\tools\EntityFramework.psm1:720 char:5 + $domain.SetData('startUpProject', $startUpProject)

I am using VS.2017 Update 1, I get the impression this "core" thing is complicating life more than making it simpler.

4/21/2017 11:02:26 PM

Popular Answer

I have do the following:

  1. Set as StartUp Project my unit test project,
  2. Set platform to Any CPU,
  3. Added an empty constructor to the Context (without calling base("name=XXX")).

Then I have issued this command Enable-Migrations

Enable-Migrations -ProjectName "MyProjectWithContext" -ConnectionString "Data Source=.\SQL;Initial Catalog=XXXXX;Integrated Security=True;MultipleActiveResultSets=True" -ConnectionProviderName System.Data.SqlClient

Same things for Add-Migration

Add-Migration -Name MyName -ProjectName "MyProject" -ConnectionString "Data Source=.\SQL;Initial Catalog=XXXX;Integrated Security=True;MultipleActiveResultSets=True" -ConnectionProviderName System.Data.SqlClient

6/22/2017 4:49:20 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow