【问题标题】:Adding migration to EF Core - error: "COM object that has been separated from its underlying RCW cannot be used"添加迁移到 EF Core - 错误:“无法使用已与其底层 RCW 分离的 COM 对象”
【发布时间】:2016-08-23 09:22:16
【问题描述】:

我一直在关注 Asp.Net Core 的以下教程:

https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html

我已经添加了工具:(Microsoft.EntityFrameworkCore.Tools –Pre),并且在向任何其他 Asp.Net MVC 项目添加迁移时照常完成,但是在运行命令时:“add-migration test”,我得到以下错误:

PM> add-migration test
add-migration : COM object that has been separated from its underlying RCW cannot be used.
At line:1 char:1
+ add-migration test
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [Add-Migration], InvalidComObjectException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.InvalidComObjectException,Add-Migration

PM> 

我已经尝试重新安装 VS2015 并重新安装 update3 和 ASP.Net Core 插件,但没有效果。

【问题讨论】:

  • 你解决了吗?如果有怎么办?
  • 对不起,我已经转移到另一个不使用 ASP.Net Core 的项目..
  • 谢谢,通过主系统命令提示符设法做到了。 cd 到项目目录并运行 dotnet ef ...
  • 感谢@Krazibit312 的提示!
  • 有没有人想办法解决这个问题,以便可以从包管理器中运行它?它对我来说工作正常,但与我一起工作的另一位开发人员遇到了这个问题,我还没有想出任何方法来解决它(尽管我确实给了他下面提到的解决方法)。

标签: entity-framework asp.net-core


【解决方案1】:

当我从 Visual Studio 中的包管理器控制台运行 cmdlet 时,我遇到了同样的问题。如https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html 中所述,我尝试从现有数据库构建模型。 这是我的解决方案(感谢@Krazibit312):

  • 我打开了命令提示符
  • 导航到项目目录
  • 然后跑了:

dotnet ef dbcontext scaffold "服务器=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o 模型

我猜你只需要为你的案例调整参数,它应该可以工作。

有关 dotnet ef 命令的更多信息,请参阅: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

【讨论】:

    猜你喜欢
    • 2011-11-21
    • 2012-04-27
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    相关资源
    最近更新 更多