我正在开发一个项目,该项目将使用 ASP.NET Web API 作为数据服务,并使用 Xamarin 便携式应用程序作为客户端。
我尝试在 Web 应用程序中启用迁移,但收到以下错误:
Enable-Migrations -enableautomaticmigrations -ContextTypeName MyProject.Models.ApplicationDbContext -ProjectName MyProject -StartupProjectName MyProject.App -Verbose
Using StartUp project 'MyProject.App'.
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 C:\Users\weitz\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5
+ $domain.SetData('project', $project)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
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 C:\Users\weitz\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:719 char:5
+ $domain.SetData('contextProject', $contextProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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.
**PM>**
正如您所看到的,我尝试显式指定启动项目,但看起来启用迁移命令对此不太满意。
这是我刚刚创建的一个使用完整 .NET 的项目(我绑定到 EF Core 尚不支持的 TPT/TPH 模型),因此 EF 版本是 6.1.3,针对 .NET 4.6.1。
我使用的是 VS Community 2015 Update 3 版本 14.0.25431.01。
Update
无法重现,但即使添加虚拟启动项目也会出现此问题。
交叉发布问题here https://github.com/aspnet/EntityFramework6/issues/317,请投票并分享您的实验。