Nah*_*uad 4 null types entity-framework
当我执行update-database命令时,它显示此错误消息
System.ArgumentNullException:值不能为null.
参数名称:类型在System.Activator.CreateInstance(类型类型,的BindingFlags bindingAttr,粘结剂粘结剂,对象[]指定参数时,CultureInfo的文化,对象[] activationAttributes)
在System.Activator.CreateInstance(类型类型,对象[]参数)
在System.Data.Entity的
System.Data.Entity.Migrations.AddMigrationCommand.Execute的System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebSiteProject(Project project) .Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project,Int32 shellVersion)
中的)
在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.AddMigrationCommand.<> c__DisplayClass2.<.ctor> b__0()
在System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action命令)值不能为空.
参数名称:类型"?
Apf*_*cha 158
对于使用 Visual Studio 2022 确实遇到此问题的用户,至少有两个修复方法:
切换回 Visual Studio 2019,因为如果您使用的是较旧的实体框架版本,它在 2022 版本中尚无法运行。
将Entity Framework更新到6.4.4即可解决
关于Entity Framework 6 GitHub 存储库上的相关问题文件,项目成员 ajcvickers于 2021-11-18 发表评论:
[...]EF 6.2 不起作用。您需要更新到 EF 6.4.4。到目前为止,我们还无法使用 EF 6.4.4 重现这一点。
尽管许多用户报告升级到 EF 6.4.4 解决了他们的问题,但问题仍然存在,因为有些用户无法降级到 Visual Studio 2019或升级实体框架,因为这些更改可能会破坏管道。
小智 34
当我使用 EF 版本 6.1.3 时,我在 VS 2022 中遇到此错误。我将 EF 升级到版本 6.4.4,问题得到解决。.Net 版本是 4.8。
解决方案:对我来说,解决方案就像重新启动visual studio一样简单.
Senario:我有这样的解决方案:
我将启动项目更改Host为UI.Web包含web.config然后运行update-database命令的项目,但它给了我Value cannot be null.异常,直到我重新启动visual studio并重新运行 update-database命令.这次它表现正常.
小智 7
Value cannot be null. (Parameter 'type')添加迁移时正好有此错误消息 ( )。尝试了其他解决方案(重新启动 VS),但没有奏效。
经过长时间的搜索,我找到了问题的根源。在我的一个 POCO 中设置“InverseProperty”注释时我犯了一个错误:
public class Workflow{
[InverseProperty("Workflow")]
public List<Node> Nodes { get; set; }
...
}
public class Node{
public int WorkflowId{ get; set; }
public Workflow Workflow{ get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
代替
public class Workflow{
[InverseProperty("WorkflowId")] //needs to be Workflow instead of WorkflowId
public List<Node> Nodes { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
我希望 EF Exception 会更精确一些。
| 归档时间: |
|
| 查看次数: |
1986 次 |
| 最近记录: |