Skip to content

Microsoft.Data.SqlClient.SNI not deployed along with WebForms #446

Open

Description

@jirikanda

Describe the bug

SNI.dll are not in build result (bin) - no x86\SNI.dll, no x64\SNI.dll is present in bin folder after WebForms project build.

To reproduce

Expected behavior

The x86\SNI.dll and x64\SNIl.dll are present in a bin folder in class library and in a bin folder of webforms.

Current behavior

The files are only in class library bin folder.

Activity

  1. mirol-h commented on Feb 26, 2020

    @mirol-h

    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.

    <!--
    ******************************************************************************
    **                           Library Build Items                            **
    ******************************************************************************
    -->
    
    <ItemGroup>
    	<SNIFiles Condition="'$(MSBuildThisFileDirectory)' != '' And
    							   HasTrailingSlash('$(MSBuildThisFileDirectory)')"
    					Include="$(MSBuildThisFileDirectory)**\SNI.*" />
    </ItemGroup>
    

    Is this expected behavior?

  2. cheenamalhotra commented on Mar 4, 2020

    @cheenamalhotra
    Member

    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!

  3. aconsolati commented on Mar 5, 2020

    @aconsolati

    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

  4. cheenamalhotra commented on Mar 5, 2020

    @cheenamalhotra
    Member

    @aconsolati

    Please see issue #441 for your case.

  5. added
    Area\Native SNI
    on Mar 7, 2020
  6. cheenamalhotra commented on Jul 30, 2020

    @cheenamalhotra
    Member

    @jirikanda

    Could you try your application with Microsoft.Data.SqlClient v2.0.0 and let us know if you still face issue?

  7. jirikanda commented on Jul 31, 2020

    @jirikanda
    Author

    @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?

  8. cheenamalhotra commented on Jul 31, 2020

    @cheenamalhotra
    Member

    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.

  9. jirikanda commented on Aug 10, 2020

    @jirikanda
    Author

    Steps to reproduce

    Current behavior

    In the class library bin\Debug\net472 folder there are these files (only bold items are important).

    • ClassLibrary1.dll
    • ClassLibrary1.pdb
    • Microsoft.Data.SqlClient.dll
    • Microsoft.Data.SqlClient.SNI.x64.dll
    • Microsoft.Data.SqlClient.SNI.x64.pdb
    • Microsoft.Data.SqlClient.SNI.x86.dll
    • Microsoft.Data.SqlClient.SNI.x86.pdb
    • Microsoft.Identity.Client.dll
    • Microsoft.IdentityModel.JsonWebTokens.dll
    • Microsoft.IdentityModel.Logging.dll
    • Microsoft.IdentityModel.Protocols.dll
    • Microsoft.IdentityModel.Protocols.OpenIdConnect.dll
    • Microsoft.IdentityModel.Tokens.dll
    • Newtonsoft.Json.dll
    • System.IdentityModel.Tokens.Jwt.dll

    In the web application bin folder there are these files:

    • ClassLibrary1.dll
    • ClassLibrary1.pdb
    • Microsoft.Data.SqlClient.dll
    • Microsoft.Identity.Client.dll
    • Microsoft.IdentityModel.JsonWebTokens.dll
    • Microsoft.IdentityModel.Logging.dll
    • Microsoft.IdentityModel.Protocols.dll
    • Microsoft.IdentityModel.Protocols.OpenIdConnect.dll
    • Microsoft.IdentityModel.Tokens.dll
    • Newtonsoft.Json.dll
    • System.IdentityModel.Tokens.Jwt.dll
    • WebApplication1.dll
    • WebApplication1.dll.config
    • WebApplication1.pdb

    Files Microsoft.Data.SqlClient.SNI.x64/x86.dll are missing.

    Expected behavior

    In the web application bin folder there are also files

    • Microsoft.Data.SqlClient.SNI.x64.dll
    • Microsoft.Data.SqlClient.SNI.x86.dll

    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)

  10. UweKeim commented on Aug 19, 2020

    @UweKeim

    Having the same issue, too. Would urgently need a working "Microsoft.SqlServer.SqlManagementObjects" NuGet package, again.

  11. ErikEJ commented on Aug 19, 2020

    @ErikEJ
    Contributor

    What if you add a Microsoft.Data.SqlClient (version 2.0.0) nuget package reference to the WebForms project?

  12. UweKeim commented on Aug 19, 2020

    @UweKeim

    Thanks, @ErikEJ, does the "Microsoft.Data.SqlClient" client also include the Management Objects?

    As a workaround I now reverted back to 150.18208.0 of the "Microsoft.SqlServer.SqlManagementObjects" which did the trick for now.

  13. jirikanda commented on Aug 20, 2020

    @jirikanda
    Author

    @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?

  14. cheenamalhotra commented on Aug 20, 2020

    @cheenamalhotra
    Member

    @jirikanda @UweKeim

    Have you tried using SMO v161.41011.9 that references Microsoft.Data.SqlClient v2.0.0 ?

  15. jirikanda commented on Aug 21, 2020

    @jirikanda
    Author

    @cheenamalhotra
    The original issue is not related to SMO. We do not need SMO in our application.

  16. 39 remaining items

  17. IgorWolbers commented on May 12, 2022

    @IgorWolbers

    @ristogod - I found the reason why this is happening. See this StackOverflow question.

     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)

  18. ristogod commented on May 12, 2022

    @ristogod

    @ristogod - I found the reason why this is happening. See this StackOverflow question.

     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.

  19. naveenxy commented on Jan 12, 2023

    @naveenxy

    I had a same issue,Add this package Microsoft.Data.SqlClient.SNI to your unit test file, resolves my isssue..

  20. hietshkumar10 commented on Jul 30, 2024

    @hietshkumar10

    I can confirm the issue...

    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?

  21. kf-gonzalez2 commented on Jul 30, 2024

    @kf-gonzalez2

    @hietshkumar10 can you make sure you are importing SNI targets file, that contains targets to perform COPY of DLL files during MsBuild tasks?

  22. hietshkumar10 commented on Jul 31, 2024

    @hietshkumar10

    @kf-gonzalez2 yes I have tried If you can specify specific file I can try that

  23. fondencn commented on May 22, 2025

    @fondencn

    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.

  24. moved this from To triage to Backlog in SqlClient Boardon Nov 26, 2025
  25. spazmodius commented on Jan 7, 2026

    @spazmodius

    I have a project DataLib that uses M.D.S.

    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.

  26. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area\Native SNI

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions