VS 2015 ASP.NET Web API(EF6)& Xamarin启用迁移失败 [英] VS 2015 ASP.NET Web API (EF6) & Xamarin Enable-Migrations fails
问题描述
我正在尝试启用在Web应用程序中的迁移,但是我收到以下错误:
启用迁移--enable自动迁移-ContextTypeName MyProject.Models.ApplicationDbContext -ProjectName MyProject -StartupProjectName MyProject.App -Verbose
使用StartUp项目'MyProject.App'。
异常使用2参数调用SetData:在程序集
'Microsoft.VisualStudio.ProjectSystem中键入'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'。 VS.Implementation,Version = 14.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'未标记为可序列化。
在C:\Users\weitz\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5
+ $ domain.SetData ('项目',$项目)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ b $ b + CategoryInfo:NotSpecified:(:) [],MethodInvocationException
+ FullyQualifiedErrorId:SerializationException
使用2参数调用SetData异常:键入Microsoft。 VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'in assembly
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,Version = 14.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'未标记为可序列化。
在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引用未设置为对象的实例。
在System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetPropertyValue [T](项目项目,String propertyName)
在System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName,Boolean useContextWorkingDirectory )
在System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
在System.Data.Entity.Migrations.EnableMigrationsCommand。 c__DisplayClass2。< .ctor> b__0()
在System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action命令)
对象引用未设置为对象的实例。
** PM> **
正如你所看到的,我试过指定明确启动项目,但看起来不像enable-migrations命令那么高兴。
这是一个使用完整的.NET(I' m绑定到EF Core不支持的TPT / TPH模型),因此EF版本是6.1.3针对.NET 4.6.1。
我是on VS Community 2015 Update 3 Version 14.0.25431.01。
更新
无法复制,但问题即使添加虚拟启动项目也会发生。
发布的问题这里,请投票并分享您的实验。
根据此(测试和工作),启用迁移的唯一方法aspnetcore + ef6项目,是在外部完整的.NET类库中添加 DbContext
,并添加一个虚拟启动项目。
吮吸但是作品。
I'm developing a project that will use ASP.NET Web API as the data service, and a Xamarin portable app as client.
I'm trying to enable migrations in the web app, but I get the following error:
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>**
As you can see, I've tried specifying the start up project explicitly but doesn't look like the enable-migrations command is so happy about it.
It's a project I just created that uses full .NET (I'm bound to TPT/TPH model which EF Core doesn't support yet), so the EF version is 6.1.3 targeting .NET 4.6.1.
I'm on VS Community 2015 Update 3 Version 14.0.25431.01.
Update
Can't reproduce, but the issue happens even when adding a dummy start up project.
Cross posted issue here, please vote and share your experiments.
Well according to this (tested and works), the only way to enable migrations in aspnetcore+ef6 project, is to have the DbContext
impl in an external full .NET class library, plus adding a dummy start up project.
Sucks but works.
这篇关于VS 2015 ASP.NET Web API(EF6)& Xamarin启用迁移失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!