2

I created an ASP.NET Core Web Application (.NET Framework) project in VS2017. Then using NuGet I installed the EntityFramework 6.1.3 (I cannot use EF Core because it does not support DbGeometry and DbGeography) .

Now when trying to to run the Enable-Migrations command in Package Manager Console it throws null reference exception.

Exception calling "SetData" with "2" argument(s): .....

System.NullReferenceException: Object reference not set to an instance of an object.

There is only one project in my solution and is set in the Default project part of the Package Manager Console. I have read this and this but non of them work in my case. Also there is not project.json file in my solution, it seems some of these answer are out of date.

Here is the snapshot of the exception message

enter image description here

EDIT: I have these packages

enter image description here

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
  • And when you just run your first add-migration? I seem to remember that enable wasn't always needed anymore. – H H Jul 03 '17 at 08:22
  • @HenkHolterman same error occurs when running first add-migration (without enabling it) – Hossein Narimani Rad Jul 03 '17 at 08:26
  • Well, "it works on my machine" .... You probably have some missing/outdated/conflicting package somewhere. Take a good look at the errors/output from restore-packages and rebuild-all. – H H Jul 03 '17 at 09:18
  • I have much more pkgs. But what might matter more, my context and model classes are not in ASP.NET Core but in Fx 4.6 projects. – H H Jul 03 '17 at 09:52
  • You may need to move the EF6 to a separate project that targets .Net 4.x as described [here](https://github.com/aspnet/Docs/issues/1830) – Steve Greene Jul 03 '17 at 13:49
  • Did you ever find a solution to this? – Shimmy Weitzhandler Sep 10 '17 at 16:22
  • I didn't solve it in Core. instead, I created a standard .net class library for the code-first project and referenced it in the Core project. So I did the code-first related jobs with that standard project and used them in the Core project. – Hossein Narimani Rad Sep 10 '17 at 16:47

1 Answers1

0

I got it working with the command EntityFrameworkCore\Add-Migration [your_migration_name]. There was no need for enable-migrations. If I was to try .NET framework standard add-migration [migration_name], the following warning would pop up:

Both Entity Framework 6.x and Entity Framework Core commands are installed. 
The Entity Framework 6 version is executing. You can fully qualify the command to select which one to execute, 'EntityFramework\Add-Migration' for EF6.x and 'EntityFrameworkCore\Add-Migration' for EF Core.'

Followed by the same exception you pasted above.

Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69