Skip to content

Microsoft.Data.SqlClient.SNI not deployed along with ClickOnce #441

Closed

Description

@Siam1205

Describe the bug

The nuget package Microsoft.EntityFrameworkCore.SqlServer v3.1.2 needs the reference to
Microsoft.Data.SqlClient.SNI v1.1.1. The SNI package is automatically added to the project when referencing the SqlServer v3.1.2 which is expected. When building the solution, the directories x64 and x86 are created as expected and everything works fine when started from the \bin\debug and \bin\release folders.

To reproduce the issue

When deploying the solution using ClickOnce, both directories (x86 and x64) are not included so that the application does not work anymore as it lacks the SNI.dll reference. I cannot see a way to solve the issue since I cannot include the reference under

ProjectName > Publish > Application Files...

I saw this (fixed) issue but for ClickOnce, it does not seem to be fixed.

Expected behavior

When deploying the application using ClickOnce, the x64 and x86 directories including the native SNI.dll libraries are copied to the respective version directory inside the "Application Files" directory and referenced properly.

Activity

  1. cheenamalhotra commented on Feb 24, 2020

    @cheenamalhotra
    Member

    Hi @Siam1205

    Are you using msbuild /target:publish to publish the same or some other tool?
    Could you try using msbuild if not already and let us know if that works?

    If not, please provide us a repro version of your ClickOnce application for us to investigate targets.

  2. cfaagaard commented on Feb 25, 2020

    @cfaagaard

    We are experiencing the same bug.
    To reproduce:

    1. Create new wfp app (.net 4.7.2)
    2. Add nuget “Microsoft.EntityFrameworkCore” (version 3.1.2)
    3. Add nuget “Microsoft.EntityFrameworkCore.SqlServer” (version 3.1.2)
    4. Build project (debug or release)
      Check bin/debug folder. It contains the two folders x64 and x86 with the SNI.dll in each folder.
      image
      If you publish same project (using visual studio 2019 (16.4.5)) the published folder looks like this:
      image
  3. Siam1205 commented on Feb 25, 2020

    @Siam1205
    Author

    Thank you very much for your Quick reply. I am currently on vacation ehich is the reason for my bad response time.

    According to your question: I am using the ClickOnce publish mechanism right from VS (I guess VS2017). Since I am on vacation I cannot try what you suggested right now. However:

    We are experiencing the same bug.
    To reproduce:

    1. Create new wfp app (.net 4.7.2)
    2. Add nuget “Microsoft.EntityFrameworkCore” (version 3.1.2)
    3. Add nuget “Microsoft.EntityFrameworkCore.SqlServer” (version 3.1.2)
    4. Build project (debug or release)
      Check bin/debug folder. It contains the two folders x64 and x86 with the SNI.dll in each folder.
      image
      If you publish same project (using visual studio 2019 (16.4.5)) the published folder looks like this:
      image

    This exactly depicts the issue. Thank you very much.

  4. Siam1205 commented on Feb 25, 2020

    @Siam1205
    Author

    I am currently using a workaround by adding both directories as content to the WPF App. This way, they are deployed along with the application. This works but is not ideal.

  5. cfaagaard commented on Feb 25, 2020

    @cfaagaard

    I am currently using a workaround by adding both directories as content to the WPF App. This way, they are deployed along with the application. This works but is not ideal.

    So do we right now :-)

  6. cheenamalhotra commented on Feb 25, 2020

    @cheenamalhotra
    Member

    Thanks for the repro @cfaagaard and @Siam1205

    I was able to reproduce the problem and saw that the SNI files were copied to Publish directory instead of deployment folder. The support for Publish Dir is for Dotnet SDK applications but there is no internal deployment folder so this was not covered.

    I was able to resolve this by adding below target to csproj:

      <Target Name="_CopySNIFilesToPublishFolder" AfterTargets="_CopyFilesToPublishFolder" 
                Condition="'$(CopySNIFiles)' != 'false' And
                          '$(_CopySNIFilesToPublishFolder)' != 'false' And
                          '$(_DeploymentApplicationDir)' != '' And
                          HasTrailingSlash('$(_DeploymentApplicationDir)') And
                          Exists('$(_DeploymentApplicationDir)')"
                Inputs="@(SNIFiles)"
                Outputs="@(SNIFiles -> '$(_DeploymentApplicationDir)%(RecursiveDir)%(Filename)%(Extension)')">
        <Copy SourceFiles="@(SNIFiles)"
              DestinationFiles="@(SNIFiles -> '$(_DeploymentApplicationDir)%(RecursiveDir)%(Filename)%(Extension)')" />
      </Target>

    Below is the output:

    image

    Let me know if you can get it working too, and we will plan to address this change in next SNI version.

  7. cfaagaard commented on Feb 26, 2020

    @cfaagaard

    I can confirm it copies the directories and the dlls and pdbs…… and it gives a warning: "Warning: Publishing file 'SNI.pdb' that may contain sensitive or proprietary information."

    In a clickonce-publish-scenario it should be sni.dll.deploy and no pdb published.

  8. cheenamalhotra commented on Feb 26, 2020

    @cheenamalhotra
    Member

    In a clickonce-publish-scenario it should be sni.dll.deploy and no pdb published.

    I agree. I think it should apply to all "Publish" targets as symbols are not needed during publish.
    I've handled that internally and will be taken care of.

  9. added this to the 2.0.0 milestone on Feb 26, 2020
  10. Siam1205 commented on Feb 27, 2020

    @Siam1205
    Author

    I will try the workaround you provided, @cheenamalhotra once I get back to work next Monday. However, according to @cfaagaard it actually works. I guess there is no need for me to additionally verify it.

    If I understand you correctly, with SqlClient v2.0.0, your <Target> workaround won't be necessary anymore?

  11. cheenamalhotra commented on Feb 27, 2020

    @cheenamalhotra
    Member

    Yes, the above target (with handled pdb case) will be part of M.D.S.SNI.targets in next release.

  12. Siam1205 commented on Mar 3, 2020

    @Siam1205
    Author
      <Target Name="_CopySNIFilesToPublishFolder" AfterTargets="_CopyFilesToPublishFolder" 
                Condition="'$(CopySNIFiles)' != 'false' And
                          '$(_CopySNIFilesToPublishFolder)' != 'false' And
                          '$(_DeploymentApplicationDir)' != '' And
                          HasTrailingSlash('$(_DeploymentApplicationDir)') And
                          Exists('$(_DeploymentApplicationDir)')"
                Inputs="@(SNIFiles)"
                Outputs="@(SNIFiles -> '$(_DeploymentApplicationDir)%(RecursiveDir)%(Filename)%(Extension)')">
        <Copy SourceFiles="@(SNIFiles)"
              DestinationFiles="@(SNIFiles -> '$(_DeploymentApplicationDir)%(RecursiveDir)%(Filename)%(Extension)')" />
      </Target>
    

    I can also confirm that this workaround solves the issue. I will use that until it becomes obsolete. Thank you very much for your efforts.

  13. Siam1205 commented on Mar 6, 2020

    @Siam1205
    Author

    Hello,

    I must add the fact that the provided workaround indeed copies the files as expected. However: While installing the latest version of the application, it does not seem to copy the files to where the whole application is deployed locally hence the workaround does not work for ClickOnce applications that are installed locally upon starting the setup.exe or the .application file in the output directory.

  14. added
    Area\Native SNI
    on Mar 7, 2020
  15. jeremy-waguet commented on Mar 31, 2020

    @jeremy-waguet

    @Siam1205
    Exactly same behaviour for me deployed but not copied locally !

    The only workaround I found is copying manually the x86 & x64 folders from the build to the deployed setup (bypassing clickonce updater ...). How to fix this properly please @cheenamalhotra ?

  16. 24 remaining items

  17. Siam1205 commented on Nov 10, 2020

    @Siam1205
    Author

    Hello @cheenamalhotra and @jeremy-waguet,

    sorry that I did not respond to you for so long and thank you for continuing to find a solution for the issue.

    The respective project still uses the workaround I mentioned on Feb 25.
    I read briefly through your discussion but I wonder what the best solution now looks like. So what's the best way to get the ClickOnce deployment working properly without manipulating too much the project itself too much?

  18. Siam1205 commented on Nov 10, 2020

    @Siam1205
    Author

    Nevertheless, I cannot check whether the ClickOnce-deployed solution works because I've encountered new problems after upgrading the packages. When I start the application, at some point I cannot access the database because of a new exception that I've never seen before:

    Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Threading.Tasks.Extensions.

    FYI: I fixed this and following issues by adding

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    

    to the corresponding .csproj file.

  19. cheenamalhotra commented on Nov 10, 2020

    @cheenamalhotra
    Member

    Hi @Siam1205

    Starting with v2.0.0 of Microsoft.Data.SqlClient, you should not have issues with Clickonce application deployments.
    Please upgrade and let us know if you face any issues! A new issue with repro in that case would be ideal.

  20. tatoadsl commented on Nov 18, 2020

    @tatoadsl

    Hello,

    This seems to be not solved or at least I can't make it work properly even trying the many workaround proposed here.
    My project is .NET 5 using EF Core 5.0. The dependency uses is Microsoft.Data.SqlClient 2.0.1 and the files are not deployed with ClickOnce.

    The problem is the same, can't find the Microsoft.Data.SqlClient.SNI.dll file as it is not copy to the deploy folder using ClickOnce publish.

    Seems it is solved when targeting a .NET Framework project but not when it is with a .NET Core project.

    Any expectation of a solution for this. Now that ClickOnce is avaiable for .NET Core projects can't be deploy properly because this issue.

    Thanks.

    PD: Not sure if this was the right place to comment on this or better to pen a new issue.

  21. MojoDK commented on Feb 22, 2021

    @MojoDK

    Why is this closed? I still have problems with SNI not deployed in ClickOnce.

  22. Siam1205 commented on Feb 22, 2021

    @Siam1205
    Author

    Starting with v2.0.0 of Microsoft.Data.SqlClient, you should not have issues with Clickonce application deployments.
    Please upgrade and let us know if you face any issues! A new issue with repro in that case would be ideal.

    I tested it with v2.0.1 now and it works as expected. Finally, I can verify that the issue has been fixed properly and entirely.

    @MojoDK It works for my C# ClickOnce application targeting NET 4.7.2. Among others, the solution contains a GUI and a Core assembly. Both include the Microsoft.Data.SqlClient v2.0.1 nuget package.

  23. MojoDK commented on Feb 22, 2021

    @MojoDK

    @Siam1205 ... Well the package says 2.1.1, but the version in VS says 2.0.20168.4:

    2021-02-22_11-36-38

    It does not work for our VB.Net ClickOnce Outlook VSTO addin. No SNI flies are being published.

  24. jeremy-waguet commented on Feb 22, 2021

    @jeremy-waguet
  25. MojoDK commented on Feb 22, 2021

    @MojoDK

    @jeremy-waguet ... that did not help. I deleted all pacakages under %userprofile%.nuget, I removed the Microsoft.Data.SqlClient from my project and added it again. When publised it throws this exception:

    System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: DLL 'Microsoft.Data.SqlClient.SNI.x64.dll' The specified module could not be found.

  26. Siam1205 commented on Feb 22, 2021

    @Siam1205
    Author

    FYI: I fixed this and following issues by adding

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    

    to the corresponding .csproj file.

    Die you try this? I also ran into the exact exception you mentioned. I fiddled with the nuget packages and managed to fix it just to get the exception i mentioned a few comments above.

    The quoted lines in combination with the newest nuget packages fixed it for me.

  27. MojoDK commented on Feb 22, 2021

    @MojoDK

    @Siam1205 ... I tried adding the two lines to the PropertyGroup of the vbproj file, but still same error and I am on latest packages.

  28. ErikEJ commented on Feb 22, 2021

    @ErikEJ
    Contributor

    @MojoDK I suggest you open a new issue, and provide a repro solution, that demonstrates the issue. Notice that a VB.NET based VSTO addin is not a standard executable app.

  29. mantasgl commented on Jan 21, 2022

    @mantasgl

    I still can get an issue when SNI deploy files are not published to ClickOnce Publishing Folder Location. These files:

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

    Although DLLs are published:

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

    Steps to reproduce:

    1. Build and Publish project with Configuration "Release".
    2. If it is the first build and publish, when SNI deploy files are published.
    3. Change Publishing Folder Location.
    4. Publish again and SNI deploy files are missing

    I tried viewing verbose build log Output and noticed that SNI target "AppendSNIDllsInManifest" is not called, because it depends on Target "BeforeBuild" and "BeforeBuild" is not called because MSBuild decides that not much have changed and no need to run many Targets.

    Same issues can be reproduced also by these things:

    • switch to other Configuration (in my case I use custom configuration) after previous successful publish and try to publish again
    • after previous successful publish, delete all files from Publishing Folder Location and try to publish again
  30. julealgon commented on Aug 12, 2023

    @julealgon

    I was having this issue with a normal "publish to folder" process. After adding SNI v.2.1.1 to the executable project, it started being copied to the publish directory correctly.

    EDIT: Upon further inspection, turns out this didn't actually solve the issue.... even though the Microsoft.Data.SqlClient.SNI DLLs were copied, the corresponding SNI.dll files under x86 and x64 folders were not...

    Back to square one...

  31. julealgon commented on Aug 12, 2023

    @julealgon

    I was having this issue with a normal "publish to folder" process. After adding SNI v.2.1.1 to the executable project, it started being copied to the publish directory correctly.

    EDIT: Upon further inspection, turns out this didn't actually solve the issue.... even though the Microsoft.Data.SqlClient.SNI DLLs were copied, the corresponding SNI.dll files under x86 and x64 folders were not...

    Back to square one...

    EDIT 2: Ok... found another post here

    Then proceed to add the Microsoft.Data.SqlClient v1.1.3 package (the version we were using in the solution) to the project. Didn't work. Then, I removed Microsoft.Data.SqlClient.SNI package and did work: the x64 and x86 folders started being copied, even though the Microsoft.Data.SqlClient.SNI dlls were not there.

    This is incredibly confusing to me but the important part is that it works now...

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

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions