You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Microsoft.Data.SqlClient.SNI not deployed along with WebForms #446
I was able to get this working by setting property ContentSNIFiles to true in ClassLibrary1.csproj.
I believe the reason, why this is not working out of the box, is that the files don't get into Content ItemGroup ClassLibrary1.csproj. And this happens, because setting Content ItemGroup in Microsoft.Data.SqlClient.SNI.targets (in the NuGet package) depends on this property not being false or empty.
I believe this is expected, as the variable "MSBuildThisFileDirectory" needs to exist in order to copy SNI files. I will take a deeper look and get back on this soon!
Related issue when running MSTests, either in Visual Studio 2019 or from command-line via vstest.console.exe.
The test run creates an output directory like the one below (eg TestResults\Deploy_Administrator 2020-03-04 11_10_41\Out), and the file Microsoft.Data.SqlClient IS copied to the \Out folder but the \x86\SNI.DLL is NOT present in the \Out folder.
Test method A_CreateDefinitionAsync threw 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.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception: Failed to load C:\Repos\Genesis\Automation\Build\TestResults\Deploy_Administrator 2020-03-04 11_10_41\Out\x86\SNI.dll ---> System.ComponentModel.Win32Exception: The specified module could not be found
if I understand the changes there are no more x86\SNI.dll and x64\SNIl.dll files, they has been replaced by Microsoft.Data.SqlClient.SNI.x86.dll and Microsoft.Data.SqlClient.SNI.x64.dll.
I recreated the project ("to reproduce" above) with the new version of Microsoft.Data.SqlClient.
Unfortunatelly, the only change is the name of files. They are present in the class library bin folder but they are not present in the web project bin folder. IMHO the issue is not fixed.
The file Microsoft.Data.SqlClient.dll is also present only in class library, not in web project. Could it be now SDK/MSBuild issue, not SqlClient?
Exception is thrown. System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll': Uvedený modul nebyl nalezen. (Exception from HRESULT: 0x8007007E)
@ErikEJ, thanks for your answer!
Of course adding Microsoft.Data.SqlClient 2.0.0 to the WebForms project makes it working. WebForms use package.config (no PackageReferences) so adding Microsoft.Data.SqlClient also adds all dependencies including Microsoft.Data.SqlClient.SNI to the package.config.
It is a good workaround which we have applied.
But who wants to manually add nuget packages to his project (WebForms) of its dependencies?
This happens because the managed dlls get shadow copied to a temporary location under the .NET Framework directory. See http://msdn.microsoft.com/en-us/library/ms366723.aspx for details.
Unfortunately, the unmanaged dlls do NOT get copied and the ASP.NET process won't be able to find them when it needs to load them.
There are some work arounds suggested in various answers but at least now I know why the error occurs.
Another GitHub related question and answer to this can be found here: #1416 (comment)
This happens because the managed dlls get shadow copied to a temporary location under the .NET Framework directory. See http://msdn.microsoft.com/en-us/library/ms366723.aspx for details.
Unfortunately, the unmanaged dlls do NOT get copied and the ASP.NET process won't be able to find them when it needs to load them.
There are some work arounds suggested in various answers but at least now I know why the error occurs.
Another GitHub related question and answer to this can be found here: #1416 (comment)
So the way we resolved this was to set IIS to a local folder and then use symbolic links to the code on the network drive. This seemed to work. So now we can deploy to a single code location, yet run multiple hosted instances of it on separate machines.
We only thought of this solution today and tested just within the last few hours. So good timing.
It does not make any sense to reference Microsoft.Data.SqlClient in the main project to solve this implicit dependency issue. I have a dedicated project to take care of data access that is referenced by the main project (web api), but the SNI stuff is not getting copied from the output of Data Layer project.
Copying them manually to the main project is not a decent solution as well. How to make visual studio copy any DLL from referenced project's bin folder to the final destination? (main project)
Any Solution?
I agree that dealing with implicit dependencies here doesn't make sense, as dependant unit test projects will break as soon as Microsoft.Data.SqlClient changes. Please fix.
I have another project MyApp that uses DataLib via a project reference. It has no inkling of M.D.S, as that is an implementation detail of the library.
When I build MyApp, it gets a copy of DataLib.dll and Microsoft.Data.SqlClient.dll, but not 'Microsoft.Data.SqlClient.SNI.x86.dll.
When I run MyApp.exe, 💥 System.DllNotFoundException: Unable to load DLL ensues.
There has got to be a non-hacktastic fix for this.
Activity
mirol-h commentedon Feb 26, 2020
I was able to get this working by setting property ContentSNIFiles to true in ClassLibrary1.csproj.
I believe the reason, why this is not working out of the box, is that the files don't get into Content ItemGroup ClassLibrary1.csproj. And this happens, because setting Content ItemGroup in Microsoft.Data.SqlClient.SNI.targets (in the NuGet package) depends on this property not being false or empty.
Is this expected behavior?
cheenamalhotra commentedon Mar 4, 2020
I believe this is expected, as the variable "MSBuildThisFileDirectory" needs to exist in order to copy SNI files. I will take a deeper look and get back on this soon!
aconsolati commentedon Mar 5, 2020
Related issue when running MSTests, either in Visual Studio 2019 or from command-line via vstest.console.exe.
The test run creates an output directory like the one below (eg
TestResults\Deploy_Administrator 2020-03-04 11_10_41\Out), and the file Microsoft.Data.SqlClient IS copied to the \Out folder but the \x86\SNI.DLL is NOT present in the \Out folder.Test method A_CreateDefinitionAsync threw 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.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception: Failed to load C:\Repos\Genesis\Automation\Build\TestResults\Deploy_Administrator 2020-03-04 11_10_41\Out\x86\SNI.dll ---> System.ComponentModel.Win32Exception: The specified module could not be foundcheenamalhotra commentedon Mar 5, 2020
@aconsolati
Please see issue #441 for your case.
cheenamalhotra commentedon Jul 30, 2020
@jirikanda
Could you try your application with Microsoft.Data.SqlClient v2.0.0 and let us know if you still face issue?
jirikanda commentedon Jul 31, 2020
@cheenamalhotra
Hi,
if I understand the changes there are no more x86\SNI.dll and x64\SNIl.dll files, they has been replaced by Microsoft.Data.SqlClient.SNI.x86.dll and Microsoft.Data.SqlClient.SNI.x64.dll.
I recreated the project ("to reproduce" above) with the new version of Microsoft.Data.SqlClient.
Unfortunatelly, the only change is the name of files. They are present in the class library bin folder but they are not present in the web project bin folder. IMHO the issue is not fixed.
The file Microsoft.Data.SqlClient.dll is also present only in class library, not in web project. Could it be now SDK/MSBuild issue, not SqlClient?
cheenamalhotra commentedon Jul 31, 2020
Could you provide us your repro with steps to deploy web project where you wish to see the files?
We do support deployment targets but it may not cover everything.
jirikanda commentedon Aug 10, 2020
Steps to reproduce
(or get the complete solution from https://github.com/jirikanda/Microsoft.Data.SqlClient-Repro2)
Current behavior
In the class library bin\Debug\net472 folder there are these files (only bold items are important).
In the web application bin folder there are these files:
Files Microsoft.Data.SqlClient.SNI.x64/x86.dll are missing.
Expected behavior
In the web application bin folder there are also files
Further steps to reproduce the issue
Exception is thrown.
System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll': Uvedený modul nebyl nalezen. (Exception from HRESULT: 0x8007007E)
UweKeim commentedon Aug 19, 2020
Having the same issue, too. Would urgently need a working "Microsoft.SqlServer.SqlManagementObjects" NuGet package, again.
ErikEJ commentedon Aug 19, 2020
What if you add a Microsoft.Data.SqlClient (version 2.0.0) nuget package reference to the WebForms project?
UweKeim commentedon Aug 19, 2020
Thanks, @ErikEJ, does the "Microsoft.Data.SqlClient" client also include the Management Objects?
As a workaround I now reverted back to
150.18208.0of the "Microsoft.SqlServer.SqlManagementObjects" which did the trick for now.jirikanda commentedon Aug 20, 2020
@ErikEJ, thanks for your answer!
Of course adding Microsoft.Data.SqlClient 2.0.0 to the WebForms project makes it working. WebForms use package.config (no PackageReferences) so adding Microsoft.Data.SqlClient also adds all dependencies including Microsoft.Data.SqlClient.SNI to the package.config.
It is a good workaround which we have applied.
But who wants to manually add nuget packages to his project (WebForms) of its dependencies?
cheenamalhotra commentedon Aug 20, 2020
@jirikanda @UweKeim
Have you tried using SMO v161.41011.9 that references Microsoft.Data.SqlClient v2.0.0 ?
jirikanda commentedon Aug 21, 2020
@cheenamalhotra
The original issue is not related to SMO. We do not need SMO in our application.
39 remaining items
IgorWolbers commentedon May 12, 2022
@ristogod - I found the reason why this is happening. See this StackOverflow question.
There are some work arounds suggested in various answers but at least now I know why the error occurs.
Another GitHub related question and answer to this can be found here: #1416 (comment)
ristogod commentedon May 12, 2022
So the way we resolved this was to set IIS to a local folder and then use symbolic links to the code on the network drive. This seemed to work. So now we can deploy to a single code location, yet run multiple hosted instances of it on separate machines.
We only thought of this solution today and tested just within the last few hours. So good timing.
naveenxy commentedon Jan 12, 2023
I had a same issue,Add this package Microsoft.Data.SqlClient.SNI to your unit test file, resolves my isssue..
hietshkumar10 commentedon Jul 30, 2024
kf-gonzalez2 commentedon Jul 30, 2024
@hietshkumar10 can you make sure you are importing SNI targets file, that contains targets to perform COPY of DLL files during MsBuild tasks?
hietshkumar10 commentedon Jul 31, 2024
@kf-gonzalez2 yes I have tried If you can specify specific file I can try that
fondencn commentedon May 22, 2025
I agree that dealing with implicit dependencies here doesn't make sense, as dependant unit test projects will break as soon as Microsoft.Data.SqlClient changes. Please fix.
spazmodius commentedon Jan 7, 2026
I have a project
DataLibthat uses M.D.S.I have another project
MyAppthat usesDataLibvia a project reference. It has no inkling of M.D.S, as that is an implementation detail of the library.When I build
MyApp, it gets a copy ofDataLib.dllandMicrosoft.Data.SqlClient.dll, but not'Microsoft.Data.SqlClient.SNI.x86.dll.When I run
MyApp.exe, 💥System.DllNotFoundException: Unable to load DLLensues.There has got to be a non-hacktastic fix for this.
priyankatiwari08 commentedon Sep 17, 2026
/triage