无法加载 DLL 'Microsoft.Data.SqlClient.SNI.x64.dll'

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

我有两个已发布的环境,一个用于测试,一个用于实时。 我发布的项目在测试环境中运行。没有任何问题,但是一旦我将它部署到实时环境上。 我收到以下错误:

ERROR 2021-06-08 16:45:34,415 455867ms ysomeController MoveNext           - System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.SNIInitialize(IntPtr pmo)
   at Microsoft.Data.SqlClient.SNILoadHandle..ctor() in H:...\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 19
   at Microsoft.Data.SqlClient.SNILoadHandle..cctor() in H:...\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 17
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.TdsParser..cctor() in H:...\Microsoft\Data\SqlClient\TdsParser.cs:line 177
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) in H:...\Microsoft\Data\SqlClient\TdsParser.cs:line 38
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) in H:...\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 1831
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) in 

更新:我还应该提到 Microsoft.Data.SqlClient.SNI.x64.dll 存在于部署后。

.net sql-server asp.net-core
4个回答
2
投票

在我的例子中,我通过 Mac 上的并行在 Windows 上运行本地 REST API。我还看到了bin中的dll。所以我检查了完整路径,即: \Mac\Home\Documents\Projects... 我想也许该路径未被识别。因此,我将项目直接复制到并行 Windows 上的另一个文件夹:C:\users cu\projects...之后一切正常。

换句话说:检查你的dll的完整路径


1
投票

所以问题出在已发布文件夹的 I/O 上。 通过将文件夹授予相关用户,问题就解决了。


1
投票

将我的项目创建为独立服务。当服务在主机上启动时,我会得到同样的错误。然后我意识到这两个 DLL 文件(Microsoft.Data.SqlClient.SNI.dll 和 sni.dll)与应用程序文件一起位于 Publish 文件夹中。我将这两个文件复制到与主机服务器上的服务应用程序文件相同的目录中。现在服务运行了!


0
投票

我通过将文件 Microsoft.Data.SqlClient.SNI.x64 复制到本地开发计算机的目录 C:\Windows\System32 来解决这个问题

这没有意义,但它有效

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