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

3

我有两个已发布的环境,一个用于测试,另一个用于生产。 我的项目在测试环境下运行没有任何问题,但是一旦我将其部署到生产环境中, 就会出现以下错误:

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 存在于 \bin 中。

请尝试更新Nuget包 Microsoft.Data.SqlClient.SNI.x64,并升级Visual Studio和操作系统至最新版本。 - undefined
请仔细检查您的应用程序配置(如果使用IIS,请确保您实际上正在运行一个Web应用程序),以验证bin文件夹是否被正确搜索以寻找二进制文件。 - undefined
这个问题一直困扰着我,目前为止,没有任何建议的解决方案可行。它是我安装的 NuGet 包的一部分,但我在 Web\BIN 文件夹下看不到 DLL 文件,也无法手动添加它。 - undefined
3个回答

0

所以问题是关于已发布文件夹的I/O。 通过将文件夹授权给相关用户,问题得到解决。


0

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


0
在我的情况下,我通过 Parallels 在我的 Mac 上本地运行了一个 rest api。我也在 bin 中看到了 dll 文件。所以我检查了完整路径,它是:\\Mac\Home\Documents\Projects... 我想也许这个路径没有被识别。所以我将我的项目直接复制到了 Parallels Windows 上的另一个文件夹中:C:\users\ncu\projects... 之后一切都正常了。
换句话说:检查你的 dll 文件的完整路径。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接