簡體   English   中英

添加遷移 asp.net web API

[英]Add Migration with asp.net web API

 
PM> Add-Migration InitialCreate
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.P
rojectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Ctop\.nuget\packages\entityframework\6.0.0\tools\EntityFramework.psm1
:609 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException
 
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.P
rojectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Ctop\.nuget\packages\entityframework\6.0.0\tools\EntityFramework.psm1
:610 char:5
+     $domain.SetData('contextProject', $contextProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException
 
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.P
rojectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Ctop\.nuget\packages\entityframework\6.0.0\tools\EntityFramework.psm1
:611 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.GetPropertyValue[T](Project project, String propertyName)
   at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)
   at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.
PM> 

我正在嘗試將遷移添加到我的 asp.net Web Api 項目,但是在添加命令 Add-Migration InitialCreate 並且我的數據庫連接正常后出現此錯誤

您是否嘗試將 Serializable 屬性設置為要序列化的 class。

 [Serializable]
    public class OrgPermission

其他答案表明這是您的啟動項目的問題。

由於您的項目是一個庫,您可以嘗試將單元測試項目設置為您的啟動項目

我只是安裝 package

Microsoft.EntityFrameworkCore.工具

並使用以下遷移命令

EntityFrameworkCore\Enable-Migrations

Add-Migration

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM