Entity Framework "update-database" fails in on dev env with error "Microsoft.VisualStudio.Data.Tools.Package is not marked as serializable"

.net-4.6.2 entity-framework-6 visual-studio-2017

Question

I recently moved from my old dev environment running VS 2015, .Net 4.5.1 on Windows 8.1 to a new environment running VS 2017, .Net 4.6.2 on Windows 10.

Previously I was able to call update-database -script from the package manager console with no problem. Though since the move I am struck with this strange error.

Has anyone else run into it, and if do you have a fix?

Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.Data.Tools.Package.Internal.OAProject' in assembly 'Microsoft.VisualStudio.Data.Tools.Package, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Workspace\Projects\XXX\main\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.UpdateDatabaseCommand.<>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 see that @lincolnzocateli makes mention of this problem here https://github.com/aspnet/EntityFramework/issues/7031 and then here https://github.com/aspnet/EntityFramework6/issues/156 but the solution is rather vague.

1
1
6/15/2017 2:02:21 PM

Popular Answer

Hate answering my own question...

The simple fix seems to be that you need to specify the startup project in packaged manager on VS 2017.

So rather than running this code

update-database

You need to run the following code

update-database -StartupProject "XXXXX"
4
6/15/2017 2:15:49 PM


Related Questions





Related

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