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
Unable to load 5.1.1 DLL 'Microsoft.Data.SqlClient.SNI.x64.dll' : The specified module could not be found. #2049
Hi,
Myself Kumar Kashyap Pandey working in .NET core (4.7.2) application and to implement Azure Active Directory authentication adding MicroSoft.Data.SqlClient for it and as per dependency MicroSoft.Data.SqlClient.SNI is also getting added but its dll is not getting loaded throwing error like Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll': The specified module could not be found.
Exception
Microft SQL Client 5.1.1 refereced in Project
SNI file not accessible error although it has read and execute access for all users.
@kumar-pandey This looks like similar known issues reported earlier: #2024#1318#745 . You should not be adding direct dependency to Microsoft.Data.SqlClient.x64.dll, it is an internal dependency of M.D.S.
I tried WebApp(MVC) netframework472 and did not see issue though, I added MDS reference to WebApp and open connection. It looks like workaround discussed here also when MDS is referenced to webapp directly #2024 (comment).
Can you provide repro and detail steps for your scenario? Can you also share if you see dll in the Publish folder.
@kumar-pandey This looks like similar known issues reported earlier: #2024#1318#745 . You should not be adding direct dependency to Microsoft.Data.SqlClient.x64.dll, it is an internal dependency of M.D.S.
I tried WebApp(MVC) netframework472 and did not see issue though, I added MDS reference to WebApp and open connection. It looks like workaround discussed here also when MDS is referenced to webapp directly #2024 (comment). Can you provide repro and detail steps for your scenario? Can you also share if you see dll in the Publish folder.
@Kaur-Parminder Thanks for considering the issue, I can't share the repo as it is a org private repo but yes for detail we want to authenticate the application through azure active directory, for that we adding the Microsoft.Data.SqlClient through Nugget package and yes the dependency dll (SNI dll) also getting installed in nugget package and its also coming in bin folder will all 86, 64 version but it can't be loaded in project. So, for trial to add that SNI dll with manual reference also through project folder but that also not worked.
Let me know if you want more details. Thanks.
@kumar-pandey Please provide details steps of how you are creating Application (Type of project) and deploying/publishing would help. if Repro is not available.
Issue reported earlier of ASP.Net/deployment are related to octopus packaging, WPF or multiple project structures and have respective workarounds. The SNI DLLs are downloaded to your bin folder when restoring/building the project if you have MDS reference. I believe you have them. Please insure you clean project before you are testing any changes.
I have created webapp(netframework472 and Microsoft.Data.SqlClient.5.1.1) and sqlclient seem to work fine. it is attached. I am hosting it locally through Visual studio 2022/2019 (IIS express).
I'm having the same issue. Trying to update our old Web Forms application and related libraries to use Microsoft.Data.Sql Client instead of System.Data.SqlClient.
The UI project has the SqlClient package as a dependency.
It always has the Microsoft.Data.SqlClient.dll file in the bin/ directory.
It sometimes doesn't have the SNI dlls in the bin directory.
After a little bit of investigation, I have found a very consistent way of reproducing the issue:
Use Visual Studio 2022 on Windows
Create a new ASP.NET Web Forms project (in my case, .NET Framework 4.7.2)
Add the Microsoft.Data.SqlClient dependency to the Web project
Rebuild in Visual Studio
SNI dll files are included in the bin/ directory
Quit Visual Studio
Delete the packages/, WebApplication/bin/ and WebApplication/obj/ directories
NOTE: We have a script to do that sometimes because Nuget, Visual Studio or something else might fail somewhere and create weird issues. This cleans everything and ensures you're building from a truly clean state.
Go back into Visual Studio and Rebuild the project
At this point, the SNI.dlls are not in the bin/ directory
It might be important to note that building the project with msbuild works every time.
Observe in the output (if your verbosity is high enough) that the SNIFiles and SNIDllFiles lists are empty
This means that none of the proposed "workarounds" currently work for me.
Instead, I will have to add a post-build script that explicitly copies the DLLs to every project's output directories.
I followed the steps as you suggested, it not worked for me, sharing the change details for target file detail in .csproj file for your verification. <Project> <ItemGroup> <AdditionalFiles Include="..\..\.sonarlint\iccm\CSharp\SonarLint.xml"> <Link>SonarLint.xml</Link> </AdditionalFiles> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\packages\Microsoft.Data.SqlClient.SNI.5.1.0\build\net462\Microsoft.Data.SqlClient.SNI.targets" Condition="Exists('..\..\packages\Microsoft.Data.SqlClient.SNI.5.1.0\build\net462\Microsoft.Data.SqlClient.SNI.targets')" /> <Target Name="SNITest" AfterTargets="AfterBuild"> <Message Text="Files: @(SNIFiles)" /> <Message Text="DLL Files: @(SNIDllFiles)" /> </Target> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"></Target><Target Name="AfterBuild"></Target> --> </Project>
@Luxed Thanks for providing detail steps. I could see error if I follow steps given above.
@Luxed@kumar-pandey after looking around more similar issues I think this is packages.config to PackageReference migration issue. Can you try make changes here: Options->NuGet Package Manager that the default package management format is PackageReference AND "Allow formation selection on first package install" is checked.
it worked consistently fine for me. if I delete bin/obj/package --> open visual studio -- build solution --> Run application
Although in above repro steps if I just clean than build on step 8 it still works. but with NP Manager changes you just have to build it.
@Kaur-Parminder Thanks for sharing the additional steps, I tried the same steps of NP Manager but it couldn't work for me, still having the same issue, hoping positively.
I think this is packages.config to PackageReference migration issue
PackageReference is simply not an option when talking about a Web Forms project. This has been discussed and documented at large. Visual Studio also stops you from converting a Web Forms project to PackageReference.
Can you try make changes here: Options->NuGet Package Manager that the default package management format is PackageReference AND "Allow formation selection on first package install" is checked.
I tried enabling "Allow format selection on first package install", but it did not change anything. And on top of that, it's also a Visual Studio/Nuget setting, so it wouldn't be suited for a development team.
This is quite a weird issue especially since I have another dependency that does a similar kind of thing (grpc, it bundles non C# dlls when building) and that one works every time.
For now, on my side, I have a documented workaround: If I build the application, then close Visual Studio, then reopen it, then build the application again, then it works for every future build (so long as you don't remove the packages directory).
This will be annoying during the transition from System.Data.SqlClient to Microsoft.Data.SqlClient, but it will eventually be less of an issue.
Have you tried 5.1.0? Comparing the packages the targets files are identical but 5.1.1 is missing the dlls in the transitive folder. The CopySNIFiles target is not locating any SNI files to copy.
The problem I have is this is an issue on the build server, so it never has the /packages/ folder already, so all of the pitfalls of deleting the folder as described above happen regardless.
Just adding in here I am seeing this happen with 5.2.0 of Microsoft.Data.SqlClient.SNI involved, but if I downgrade to 5.1.1, I do get the SNI.x64 DLL in my build. This is for a .NET 4.8 project. Not sure if that helps any, I can't provide the project as a ref due to ownership.
If I discover anything else in my case I'll report back.
All required environment details provided for investigation
Area
Area\Native SNI
Duplicates
Potentially related: #612, #766, #936, #2151, #2671, #3342, #2998, #2824 (all concern Microsoft.Data.SqlClient.SNI native DLL not being deployed/loaded correctly across various project types)
Regression
Likely regression from v5.1.0 (comment from @kurt-m shows the CopySNIFiles MSBuild target fails to locate/copy SNI DLLs starting with v5.1.1, and @gilmorem560 confirms downgrading to 5.1.1 restores the DLL on .NET Framework 4.8 vs 5.2.0)
Analysis
The reporter (.NET Framework 4.7.2, Microsoft.Data.SqlClient.SNI 5.1.1) hits DllNotFoundException for Microsoft.Data.SqlClient.SNI.x64.dll because the native SNI assembly is not being copied to the output/bin folder. This is already tracked under parent meta-issue #4129 ("SNI loading issues") and is corroborated by multiple commenters describing the same root cause: the CopySNIFiles MSBuild target in the SNI NuGet package fails to locate/copy the native DLL into the transitive dependencies folder, particularly for packages.config-based Web Forms/legacy projects that cannot migrate to PackageReference. Severity: P2 (workaround exists — closing/reopening Visual Studio, or pinning to 5.1.0 — but it blocks builds on CI/build servers where the packages folder does not pre-exist, per @lordscarlet).
Next Steps
Given the mature, well-documented repro and existing linked issues, assign this issue to Copilot coding agent to investigate the CopySNIFiles MSBuild target and packaging logic in the Microsoft.Data.SqlClient.SNI NuGet package (targets file) to determine why native DLLs are not copied into the transitive/output folder for packages.config-based .NET Framework projects, and to compare with the working 5.1.0 targets file logic referenced by @kurt-m.
Since a regression boundary (5.1.0 → 5.1.1) was identified in comments, bisection of the SNI package's targets/props changes between those versions is recommended to confirm the root cause before implementing a fix.
Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.
Activity
Kaur-Parminder commentedon Jun 5, 2023
@kumar-pandey This looks like similar known issues reported earlier: #2024 #1318 #745 . You should not be adding direct dependency to Microsoft.Data.SqlClient.x64.dll, it is an internal dependency of M.D.S.
I tried WebApp(MVC) netframework472 and did not see issue though, I added MDS reference to WebApp and open connection. It looks like workaround discussed here also when MDS is referenced to webapp directly #2024 (comment).
Can you provide repro and detail steps for your scenario? Can you also share if you see dll in the Publish folder.
kumar-pandey commentedon Jun 7, 2023
@Kaur-Parminder Thanks for considering the issue, I can't share the repo as it is a org private repo but yes for detail we want to authenticate the application through azure active directory, for that we adding the Microsoft.Data.SqlClient through Nugget package and yes the dependency dll (SNI dll) also getting installed in nugget package and its also coming in bin folder will all 86, 64 version but it can't be loaded in project. So, for trial to add that SNI dll with manual reference also through project folder but that also not worked.
Let me know if you want more details. Thanks.
Kaur-Parminder commentedon Jun 7, 2023
@kumar-pandey Please provide details steps of how you are creating Application (Type of project) and deploying/publishing would help. if Repro is not available.
Issue reported earlier of ASP.Net/deployment are related to octopus packaging, WPF or multiple project structures and have respective workarounds. The SNI DLLs are downloaded to your bin folder when restoring/building the project if you have MDS reference. I believe you have them. Please insure you clean project before you are testing any changes.
I have created webapp(netframework472 and Microsoft.Data.SqlClient.5.1.1) and sqlclient seem to work fine. it is attached. I am hosting it locally through Visual studio 2022/2019 (IIS express).
WebApplication2dllloading.zip
Luxed commentedon Jun 8, 2023
I'm having the same issue. Trying to update our old Web Forms application and related libraries to use
Microsoft.Data.Sql Clientinstead ofSystem.Data.SqlClient.The UI project has the SqlClient package as a dependency.
It always has the
Microsoft.Data.SqlClient.dllfile in thebin/directory.It sometimes doesn't have the
SNIdlls in the bin directory.After a little bit of investigation, I have found a very consistent way of reproducing the issue:
Microsoft.Data.SqlClientdependency to the Web projectbin/directorypackages/,WebApplication/bin/andWebApplication/obj/directoriesNOTE: We have a script to do that sometimes because Nuget, Visual Studio or something else might fail somewhere and create weird issues. This cleans everything and ensures you're building from a truly clean state.
SNI.dlls are not in thebin/directoryIt might be important to note that building the project with
msbuildworks every time.Luxed commentedon Jun 8, 2023
After more investigation on my side, I have found something else.
The following part in the target:
Seem to be returning empty lists when the bug appears.
I have tried this:
Microsoft.Data.SqlClient.SNI.targetsfile to include this after the ItemGroup:This means that none of the proposed "workarounds" currently work for me.
Instead, I will have to add a post-build script that explicitly copies the DLLs to every project's output directories.
kumar-pandey commentedon Jun 9, 2023
Thanks Luxed for guiding for resolving my issue
I followed the steps as you suggested, it not worked for me, sharing the change details for target file detail in .csproj file for your verification.
<Project> <ItemGroup> <AdditionalFiles Include="..\..\.sonarlint\iccm\CSharp\SonarLint.xml"> <Link>SonarLint.xml</Link> </AdditionalFiles> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\packages\Microsoft.Data.SqlClient.SNI.5.1.0\build\net462\Microsoft.Data.SqlClient.SNI.targets" Condition="Exists('..\..\packages\Microsoft.Data.SqlClient.SNI.5.1.0\build\net462\Microsoft.Data.SqlClient.SNI.targets')" /> <Target Name="SNITest" AfterTargets="AfterBuild"> <Message Text="Files: @(SNIFiles)" /> <Message Text="DLL Files: @(SNIDllFiles)" /> </Target> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"></Target><Target Name="AfterBuild"></Target> --> </Project>Please verify, if it is correct.
Thanks,
Kumar
Luxed commentedon Jun 9, 2023
I'm not able to fix the issue either. The steps I wrote are only here to help reproduce the issue.
Kaur-Parminder commentedon Jun 10, 2023
@Luxed Thanks for providing detail steps. I could see error if I follow steps given above.
@Luxed @kumar-pandey after looking around more similar issues I think this is packages.config to PackageReference migration issue. Can you try make changes here: Options->NuGet Package Manager that the default package management format is PackageReference AND "Allow formation selection on first package install" is checked.
it worked consistently fine for me. if I delete bin/obj/package --> open visual studio -- build solution --> Run application
Although in above repro steps if I just clean than build on step 8 it still works. but with NP Manager changes you just have to build it.
kumar-pandey commentedon Jun 12, 2023
@Kaur-Parminder Thanks for sharing the additional steps, I tried the same steps of NP Manager but it couldn't work for me, still having the same issue, hoping positively.

Luxed commentedon Jun 12, 2023
PackageReference is simply not an option when talking about a Web Forms project. This has been discussed and documented at large. Visual Studio also stops you from converting a Web Forms project to PackageReference.
I tried enabling "Allow format selection on first package install", but it did not change anything. And on top of that, it's also a Visual Studio/Nuget setting, so it wouldn't be suited for a development team.
This is quite a weird issue especially since I have another dependency that does a similar kind of thing (grpc, it bundles non C# dlls when building) and that one works every time.
For now, on my side, I have a documented workaround: If I build the application, then close Visual Studio, then reopen it, then build the application again, then it works for every future build (so long as you don't remove the
packagesdirectory).This will be annoying during the transition from
System.Data.SqlClienttoMicrosoft.Data.SqlClient, but it will eventually be less of an issue.kurt-m commentedon Oct 31, 2023
Have you tried 5.1.0? Comparing the packages the targets files are identical but 5.1.1 is missing the dlls in the transitive folder. The CopySNIFiles target is not locating any SNI files to copy.
lordscarlet commentedon Jan 26, 2024
The problem I have is this is an issue on the build server, so it never has the
/packages/folder already, so all of the pitfalls of deleting the folder as described above happen regardless.gilmorem560 commentedon Jul 23, 2024
Just adding in here I am seeing this happen with 5.2.0 of Microsoft.Data.SqlClient.SNI involved, but if I downgrade to 5.1.1, I do get the SNI.x64 DLL in my build. This is for a .NET 4.8 project. Not sure if that helps any, I can't provide the project as a ref due to ownership.
If I discover anything else in my case I'll report back.
jzabroski commentedon Nov 21, 2024
@Luxed , thanks for your comment here: #2049 (comment)
Have you tried taking an msbuild binary log file and viewing it in MSBuild Structured Log Viewer tool? https://msbuildlog.com/
I am curious if you see the same behavior I describe here: dotnet/msbuild#10973 (comment)
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\Native SNIMicrosoft.Data.SqlClient.SNInative DLL not being deployed/loaded correctly across various project types)@kurt-mshows theCopySNIFilesMSBuild target fails to locate/copy SNI DLLs starting with v5.1.1, and@gilmorem560confirms downgrading to 5.1.1 restores the DLL on .NET Framework 4.8 vs 5.2.0)Analysis
The reporter (.NET Framework 4.7.2,
Microsoft.Data.SqlClient.SNI5.1.1) hitsDllNotFoundExceptionforMicrosoft.Data.SqlClient.SNI.x64.dllbecause the native SNI assembly is not being copied to the output/bin folder. This is already tracked under parent meta-issue #4129 ("SNI loading issues") and is corroborated by multiple commenters describing the same root cause: theCopySNIFilesMSBuild target in the SNI NuGet package fails to locate/copy the native DLL into the transitive dependencies folder, particularly forpackages.config-based Web Forms/legacy projects that cannot migrate toPackageReference. Severity: P2 (workaround exists — closing/reopening Visual Studio, or pinning to 5.1.0 — but it blocks builds on CI/build servers where thepackagesfolder does not pre-exist, per@lordscarlet).Next Steps
CopySNIFilesMSBuild target and packaging logic in theMicrosoft.Data.SqlClient.SNINuGet package (targets file) to determine why native DLLs are not copied into the transitive/output folder forpackages.config-based .NET Framework projects, and to compare with the working 5.1.0 targets file logic referenced by@kurt-m.RuntimeIdentifierproperty #2671, Microsoft.Data.SqlClient.SNI.dll: "not supported on this platform" #3342, Improve SNI package architecture and targets file design #2998, How to prevent publishing SNI dll when using AppContext switch for managed networking? #2824) — several describe the same transitive-copy failure across different project types (MSIX, ClickOnce, WRAPPROJ, RuntimeIdentifier handling) and may share a common root cause worth consolidating under parent issue SNI loading issues #4129.