Ef6: Migration commands crash when running against an SDK-based csproj

Created on 24 Mar 2017  路  13Comments  路  Source: dotnet/ef6

I've encountered this problem when trying to convert a project to the new SDK-based csproj. It had worked fine until I tried to add a new migration, which crashed with the following 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, Publ
icKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\HellBrick\.nuget\packages\entityframework\6.1.3\tools\EntityFramework.psm1:720 char:5
+     $domain.SetData('startUpProject', $startUpProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetPropertyValue[T](Project project, String propertyName)
   at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)
   at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
   at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.

You can easily reproduce this with a new project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="EntityFramework" Version="6.1.3" />
  </ItemGroup>
</Project>
using System.Data.Entity;
namespace EntityFrameworkNewCsprojTest
{
    public class SomeEntity
    {
        public int ID { get; set; }
        public int Name { get; set; }
    }

    public class TestContext : DbContext
    {
        public DbSet<SomeEntity> SomeEntities { get; set; }
    }

    internal class Program
    {
        static void Main( string[] args ) {}
    }
}

Running Enable-Migrations against it will cause the same error.

This is a very unpleasant blocker for us, is there any way to at least work around this problem?

closed-duplicate

Most helpful comment

@bricelam - In above image, EFCore\Enable-Migrations says to use EF\Update-Database for EF6. which would be incorrect. Can you verify, we are doing correct thing?

All 13 comments

Use a standard "Classic" class library?

That's what we're doing today =) The old csproj format works, but the whole point of this issue is to figure out how to migrate to the new csproj format while keep using EF 6.

You will be entering a world of pain, suggest you wait for a new EF version (ie 6.3) with support for new project format https://github.com/NuGet/Home/issues/4876

"World of pain" is a relative term, the old csproj isn't that pleasant to deal with either ;) If this can't be done without some substantial engineering work in the EF codebase, then there's no other choice but to wait for the update. However, if it's possible to make migrations work via some manual adjustments to project file/app.config/migration script/whatever, then it might just be worth it.

Closing this as a dupe of #231, which we are investigating.

@ajcvickers Think you forgot to actually close?

@ErikEJ Thanks. You are our process bot. 馃槈

Sorry! :smile:

@ErikEJ Don't apologize. It is much appreciated. 馃樃

@DeshmukhParag could you please explain the intent of your previous comment? Is there something not working according to your expectations?

@bricelam - In above image, EFCore\Enable-Migrations says to use EF\Update-Database for EF6. which would be incorrect. Can you verify, we are doing correct thing?

Was this page helpful?
0 / 5 - 0 ratings