Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll'

I have two published environment, one for test and one for live. my published project works in test env. without any issue, but as soon as I deploy it on live env. I get the following error:

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 

Updated: I also should mention that Microsoft.Data.SqlClient.SNI.x64.dll exists in \bin after deployment.

like image 719
Ocelot Avatar asked Sep 07 '25 05:09

Ocelot


2 Answers

In my case I was running a rest api local on Windows via parallels on my mac. I also saw the dlls in bin. So I checked the full path, which was: \\Mac\Home\Documents\Projects... I figured maybe that path is not recognised. So I copied my project to a different folder directly on my parallels Windows: C:\users\ncu\projects... After that everything worked.

In other words: Check the full path to your dll's

like image 167
Niels Avatar answered Sep 10 '25 12:09

Niels


So the problem was about the I/O of published folder. By granting the folder to related user the problem solved.

like image 21
Ocelot Avatar answered Sep 10 '25 12:09

Ocelot