【问题标题】:Microsoft.Data.SqlClient is not supported on this platform - Entity Framework Core 3.1此平台不支持 Microsoft.Data.SqlClient - Entity Framework Core 3.1
【发布时间】:2020-10-12 07:57:55
【问题描述】:

我在 .NET Core 3.1 库中使用 Microsoft.EntityFrameworkCore.SqlServer (3.1)。该库在运行时由可执行的 .NET Core 项目加载,方法是:

Assembly.LoadFrom('some.dll');

尝试从 DbSet 检索数据时,我收到以下异常:

System.PlatformNotSupportedException: '此平台不支持 Microsoft.Data.SqlClient。'

我猜这与在运行时加载库有关,但我不明白为什么?

我尝试了各种不同的方法,例如用 1.1 或 2.0 版本覆盖 Microsoft.Data.SqlClient 库,但没有任何成功。

【问题讨论】:

标签: c# .net-core entity-framework-core ef-core-3.1 entity-framework-core-3.1


【解决方案1】:

我收到了这条消息: System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.

我的解决方案:

  • 将最新版本的 Microsoft.Data.SqlClient 添加为 NuGet 依赖项(当前 v.2.1.2)
  • 如果您使用 Newtonsoft 命名空间,例如安装Microsoft.Data.SqlClient后找不到Newtonsoft.Json和这个命名空间,然后从NuGet获取Newtonsoft.Json依赖。

【讨论】:

    【解决方案2】:

    到目前为止,我发现的唯一解决方法是将“Microsoft.EntityFrameworkCore.SqlServer”添加到可执行项目中。不优雅,但很有效。

    【讨论】:

    • 您是保留还是删除 Microsoft.Data.SqlClient 依赖项?我已将所有内容更新为 .Net5.0,SqlClient 似乎是尚未更新的一件事。
    【解决方案3】:

    我遇到了同样的问题,只需将 bin 文件夹(不仅是 .dll 文件)重新上传到生产服务器即可解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 2021-04-23
      相关资源
      最近更新 更多