当我从控制台程序运行 C# .NET 6.0 库时,我没有遇到任何问题System.Data.SqlClient
或 Microsoft.Data.SqlClient 我用两个 DLL 进行了测试,但是如果我用另一个 DLL 调用该 DLL.exe
在 .NET 6.0 中的程序中,我遇到两个 dll System.Data.SqlClient` 或 Microsoft.Data.SqlClient 以及 oledb dll 的异常。
System.PlatformNotSupportedException:此平台不支持 System.Data.SqlClient
My code:
using (var connection = new SqlConnection(connectionString))
{
using (var cmd = new SqlCommand(queryString, connection))
{
cmd.Connection = connection;
connection.Open();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
return true;
}
}
}
}
我的 CSProj 文件 https://i.stack.imgur.com/pIkSr.png
Exeption https://i.stack.imgur.com/EXS6U.png
对我来说,在 Server.Project.cs 文件中添加目标操作系统平台解决了这个问题。
<RuntimeIdentifier>ubuntu.22.04-x64</RuntimeIdentifier>
在终端中使用“dotnet --info”找到您的目标操作系统平台(对我来说是“ubuntu.22.04-x64”),然后将其添加到您的 proj.cs 文件中。
运行环境:
操作系统名称:linuxmint
操作系统版本:21.1
操作系统平台:Linux
RID:ubuntu.22.04-x64
基本路径:/usr/lib/dotnet/sdk/7.0.109/
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>ubuntu.22.04-x64</RuntimeIdentifier>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
基本上,根据我经过几个小时的研究收集到的信息......
Microsoft.Data.SqlClient 有多个适用于不同目标平台的 DLL。由于某种原因,加载了错误的文件。你可以用我提供的方法明确指定要加载哪个dll。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)