DllNotFoundException: Unable to load DLL 'sni.dll': Access is denied.
See original GitHub issueSteps to reproduce
dotnet publish -c Production
copy files to a windows 2012 r2 iis8.5 machine with the hosting bundle installed.
λ dotnet --version
Microsoft .NET Core Shared Framework Host
Version : 1.1.0
Build : 928f77c4bc3f49d892459992fb6e1d5542cb5e86
Expected behavior
I expect the application to work when published to IIS when using a sql client like it does when run on OSX.
Actual behavior
An unhandled exception occurred while processing the request.
DllNotFoundException: Unable to load DLL 'sni.dll': Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
TypeInitializationException: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception.
System.Data.SqlClient.TdsParser..cctor()
TypeInitializationException: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.
System.Data.SqlClient.TdsParser..ctor(bool MARS, bool fAsynchronous)
Environment data
dotnet --info
output:
$ dotnet --info
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (1 by maintainers)
Top Results From Across the Web
Unable to load DLL 'sni.dll' - Entity Framework Core
In some instances this issue can be caused by IIS not having sufficient permissions to access areas of your %USERPROFILE%.nuget.
Read more >Jitbit Helpdesk - Unable to load DLL 'sni.dll': Access is denied
dll': Access is denied" error in the server "event viewer" this means the app has trouble connecting to the database server. This is...
Read more >Unable to load DLL 'sni.dll' or one of its dependencies
1 in Visual Studio and I get this error. System.DllNotFoundException: 'Unable to load DLL 'sni.dll' or one of its dependencies: Access is denied....
Read more >Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll'
I have two published environment, Staging and one for live. my published project works in test env. without any issue, but as soon...
Read more >System.DllNotFoundException: Unable to load DLL 'sni.dll' or ...
This message happens when deploying my .NET Core 3.1 application to production (when compiling the code to an .exe file), ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Had the same issue. Fixed it by assigning full control to %USERPROFILE%.nuget. You can also try to change the app pool identity in IIS to LocalSystem.
This happen with me. Giving more permissions to the Application Pool user for me is the worst option, for God’s sake! For who don’t know, the Application Pool Identity was created to give more security to the entire server!!
https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities
All my sites run with Application Pool Identity, with “Read” only permission to IISAppPool\APPLICATIONPOOLNAME to the site’s folder.
With .NET Core i’m having this problem with some sites, that could be solved by giving ONLY the folder’s DLL the “Read and Execute” permission solve the problem. (In that case of “sni.dll”, giving “Read and Execute” to […]\runtimes\win-arm64\native should work). If you don’t want to debug to the correct way, this is, in my opinion, by far, best than giving “System” permission to the App Pool)
But it’s not how should be, in my opinion, as “Execute” permission give a security flaw as someone could inject a code in that folder and execute remotely.
Something is making the AppPoolIdentity need to execute the DLLs needed to access SQL Server.