我正在開發將使用的ASP.NET Web API作爲數據服務的項目,以及Xamarin便攜式應用的客戶端。VS 2015年的ASP.NET Web API(EF6)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>**
正如你所看到的,我已經試過指定啓動項目明確,但不看像enable-migrations命令對此非常高興。
這是我剛剛創建了一個項目,該項目使用完整的.NET(我一定到EF核心還不支持TPT/TPH模型),所以EF版本是6.1.3針對.NET 4.6.1。
我在VS 2015年社區更新3版本14.0.25431.01。
更新
無法重現,但添加一個虛擬的啓動項目時,這個問題甚至發生。
Cross發佈問題here,請投票並分享您的實驗。
您的啓動項目是否包含您用來連接數據庫的app.config或web.config?您也可以使用包含dbcontext的項目作爲啓動項目。 – jomsk1e
它使用appsettings.json來存儲連接字符串。但我嘗試將連接字符串添加到app.config,但它沒有幫助。 – Shimmy