EF 更新数据库错误:值不能为空参数名称:类型

问题描述 投票:0回答:3

我尝试在 PMC 中执行命令

update-database
,但总是收到此错误消息。我知道还有另一篇文章基本上有相同的错误,但我尝试了每个答案,但没有任何效果。

System.ArgumentNullException: Value cannot be null.
Parameter name: type

at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebSiteProject(Project project)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetTargetDir(Project project)
at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

Value cannot be null.
Parameter name: type

顺便说一句,我正在使用 VS2022 预览版。

c# .net entity-framework code-first
3个回答
48
投票

尝试将 EntityFramework 包更新到最新版本。 我在 EF 6.1.3 上遇到了同样的问题,但后来更新到 6.4.4,它在 VS2022 预览版上运行良好。


1
投票

使其工作的另一种方法是使用 VS2019。

当您安装Entity

Framework 6.3 <
时,您将看到以下消息:

A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Update-Database' for the older version.

工具已更新,不幸的是,通过包管理器控制台运行命令时,Visual Studio 2022 与旧版实体框架不兼容


0
投票

我在

connection
参数上遇到了这个问题。我的问题是我试图使用一个正在回滚的事务来执行 SQL,以测试迁移是否有效。一旦我删除了
BEGIN/ROLLBACK TRAN
语句,它就起作用了。

© www.soinside.com 2019 - 2024. All rights reserved.