runtime: SQL Client: Unable to load sni.dll (DllNotFoundException)

Several customers have reported errors loading sni.dll.

This is not the same as https://github.com/dotnet/corefx/issues/3760 because installing the Microsoft Visual C++ 2012 Redistributable does not resolve the issue.

Examples of the customer reports are on https://github.com/aspnet/EntityFramework/issues/4162. Many of those are seeing the error when using EF7 but have confirmed that the error reproduces when using SQL Client directly.

Several people have reported that the error occurs under the following environment

coreclr-x64-rc1-update1 with IIS 7.5 on Windows Server 2008 R2 with C++ redistributable installed (x64 & x86).

Full details of the exception…

The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.Exception caught: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception.Exception caught: Unable to load DLL 'C:\Users\ddragan\.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23616\runtimes\win7-x64\native\sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)Exception thrown: 'System.TypeInitializationException' in Platform.Authentication
Exception thrown: 'System.TypeInitializationException' in mscorlib.ni.dll
Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware:Error: An unhandled exception has occurred: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.
System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'C:\Users\ddragan\.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23616\runtimes\win7-x64\native\sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(String unmanagedDllPath)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.LoadUnmanagedLibrary(String name)
   at Microsoft.Dnx.Host.LoaderContainer.LoadUnmanagedLibrary(String name)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadUnmanagedDll(String unmanagedDllName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext)
   at System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
   at System.Data.SqlClient.SNILoadHandle..ctor()
   at System.Data.SqlClient.SNILoadHandle..cctor()
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.TdsParser..cctor()
   --- End of inner exception stack trace ---
   at ExternalDataAccessor.GetFirm(String firmName)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 42 (17 by maintainers)

Most upvoted comments

When publishing web project, it will create AppRoot/web.cmd IIS will execute this Web.cmd and it will execute DNX.exe.

Unfortunately this web.cmd doesn’t register your runtime (which should be on your current publish package). So it will use any runtime that you installed in your user profile.

In IIS, by default it will run your web application with “ApplicationPoolIndentiy” user, But your DNX runtime was installed under your local user. This is the root cause why you get sni.dll loader exception. Because it is depend on api-ms-win-core-stringansi-l1-1-0.dll which should be located inside your runtime.

In other cases, this will lead to the different runtime version. E.g you published x64 version, but you set your current dnvm environment with x86. When you run this using approot/web.cmd, this will use x86 runtime which will cause exception to load native dll

For workaround, you can modify web.cmd to add your runtime into your path. SET “PATH=%PATH%;%~dp0runtimes%DNX_FOLDER%\bin;”

It should look like this.

@echo off
SET DNX_FOLDER=dnx-coreclr-win-x64.1.0.0-rc1-update1
SET "LOCAL_DNX=%~dp0runtimes\%DNX_FOLDER%\bin\dnx.exe"
SET "PATH=%PATH%;%~dp0runtimes\%DNX_FOLDER%\bin\;"

Restart your IIS, it should solve your problem.


I will raise issue with DNX/CLI team.