使用asp.net Web API添加迁移

ercv8c1e  于 2022-12-14  发布在  .NET
关注(0)|答案(2)|浏览(199)
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后出现此错误,并且数据库连接正常工作

u3r8eeie

u3r8eeie1#

是否尝试将Serializable属性添加到要序列化的类。

[Serializable]
    public class OrgPermission

其他答案表明这是启动项目的问题。
由于您的项目是库,因此可以尝试将单元测试项目设置为启动项目

z3yyvxxp

z3yyvxxp2#

我只是安装软件包
Microsoft.EntityFrameworkCore.Tools
并使用以下迁移命令

EntityFrameworkCore\Enable-Migrations

Add-Migration

相关问题