Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll':

Dave Gray 586 Reputation points
2023-12-09T12:14:29.8766667+00:00

Hi,

Have a .NET framework (4.8 ) console application that uses SQL 2022 via the nuget packages Microsoft.Data.SqlClient and .SqlClient.SNI. The app is built into an executable via a stetup/installer project (https://marketplace.visualstudio.com/items?itemName=VisualStudioClient.MicrosoftVisualStudio2022InstallerProjects)

When I debug my project all works as expected, however when I build the EXE and run it from the command like I get this error

Unhandled Exception: 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.x86.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I used to use System.Data.SqlClient but switched Microsoft.Data.SqlClient for this new project.

Do I need to reference Microsoft.Data.SqlClient in my setup project?

Thanks

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
42,019 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.