9

I have a new ASP.net 5 dnx class library I am using for entity framework. I need to target EF 6 because some features I need are not in EF 7.

First the EF tools (like enable-migration) were not there. I added an old style class library and installed EF 6 and now the commands are there.

When I run enable migrations I get this error:

PM> Enable-Migrations

Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At D:\Projects\Rebus\FMS\Code\Current\FMSSupport\FMSSupport\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.GetProjectTypes(Project project, Int32 shellVersion) at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project) 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.

I have tried different options for enable-migration such as specifying a startup project or the contextTypeName.

Any ideas?

Raskolnikov
  • 3,791
  • 9
  • 43
  • 88
Don Chambers
  • 3,798
  • 9
  • 33
  • 74
  • I got this with a normal ASP.NET project... – leppie Mar 11 '16 at 13:06
  • 1
    Hehe, 'start up' caught my eye. I set web project as startup project, and then it worked :D – leppie Mar 11 '16 at 13:07
  • Did you find a solution to this? I wanted ComplexType support which EFCore doesn't currently support. ATM I'm looking at having to manually unwind the complextypes in order to use EFCore :( – Ilan Jul 04 '16 at 07:16
  • @Raskolnikov This question is not really useful. DNX is dead. You should upgrade to the release version of ASP.NET Core with the .NET Core CLI. A lot has changed about the project format which makes answers to this question very irrelevant to anything since the tooling no longer exists and you couldn’t reproduce anything. – poke Nov 16 '16 at 14:53
  • Same issue on .Net Core 1.0 – Raskolnikov Nov 16 '16 at 15:03
  • @Raskolnikov Then please create a new question instead. This question is not helpful in its current state and difficult to salvage. – poke Nov 16 '16 at 16:17
  • Did you follow this guideline https://learn.microsoft.com/en-us/aspnet/core/data/entity-framework-6 ? Did you create a parameter less constructor? And all other requirements outlined here? It is useless to create ASP.NET Core with EF6 as it will not run on non windows platform anyway. – Akash Kava Nov 23 '16 at 07:47

3 Answers3

4

Following this recommendation, EF6 data projects should use the existing .NET Framework class library csproj type.

Even after following the recommendations, I was still getting the same error. Unloading your ASP.NET Core project(s) and then invoking the Enable-Migrations command on the appropriate csproj should allow the command to execute. You can unload a project by right-clicking on the .NET Core project and choosing the 'Unload Project' option. It should also be noted that the Package Manager Console window has a 'Default project:' drop-down selection. You should choose the project with your DbContext.

deloreyk
  • 1,248
  • 15
  • 24
1

It's because ASP.NET Core introduced a new project type/configuration system (see package.config vs project.json) and the old EF tools don't know how to work with the newer system (project.json). It would probably be easiest to create a new project and port your code into it if you want to go back to EF6.

Interestingly (well, disappointingly actually) they're backtracking on project.json see: http://xoofx.com/blog/2016/05/11/goodbye-project-json/

Ilan
  • 1,647
  • 1
  • 15
  • 16
0

I had the same issue. Just setting the start project from ASP.NET Core to my .NET Framework Lib does the trick for me =) Now i can do EF6 migrations as usual "Add-Migration" command...

P.S. Sorry for my eng.

Vladislav
  • 218
  • 1
  • 13