2

I wanted to get started using EF and followed Microsofts docs. Everything builds fine but when I try to create the initial migration PM throws an exception.

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\Anton\.nuget\packages\entityframework\6.2.0\tools\EntityFramework.psm1:720 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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)

I have googled a lot and found other people having the same problem. I have tried all the solutions there, especially the ones including setting the startup project but that does not seem to work. For example running -StartupProjectName WebApplication1 just throws an error saying that -StartupProjectName does not exist. If I download an example project that uses EF however, migrations seem to work. I have also tried creating a class lib project and done the migrations there but it has the same result.

Essej
  • 892
  • 6
  • 18
  • 33
  • The linked tutorial is for EF Core, while you seem to be using EF6.2. Also, what version of VS are you on? The prerequisite states you need at minimum VS2017 15.3 – Ivan Stoev Jul 06 '18 at 11:18
  • I'm on the very latest VS17. I didn't realize there were different versions of EF. I want to develop a .net Core API that uses EF, which EF should I use? – Essej Jul 06 '18 at 11:30
  • I guess [Entity Framework Core](https://learn.microsoft.com/en-us/ef/core/). See also [EF Core and EF6: Which One Is Right for You](https://learn.microsoft.com/en-us/ef/efcore-and-ef6/choosing). – Ivan Stoev Jul 06 '18 at 11:32
  • 1
    Thanks a million, already wasted several hours on this! Please write it as an answer so I can mark it as solved. – Essej Jul 06 '18 at 11:36
  • Are you wanting to do "Code First" or "Database First" development? – Troy Turley Jul 06 '18 at 11:38
  • You are welcome, glad it helped :) But I'll stay with comments, feel free to post a self answer. – Ivan Stoev Jul 06 '18 at 11:42
  • Code First approach. The problem was that I installed EF6 from the package manager GUI, I did not know there was a special version for Core. I haven't seen that in the package manager. – Essej Jul 06 '18 at 11:43
  • Here are step-by-step instructions for "Code First". https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db – Troy Turley Jul 06 '18 at 11:54
  • As Ivan's link mentions, many of us use EF6 with .NET Core. – Steve Greene Jul 06 '18 at 13:55

1 Answers1

4

As @Ivan Stoev pointed out, I was using the wrong EF version. Here is a short article explaining the difference between EF and EF Core.

Essej
  • 892
  • 6
  • 18
  • 33