runtime icon indicating copy to clipboard operation
runtime copied to clipboard

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

Open rowanmiller opened this issue 10 years ago • 42 comments

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)

rowanmiller avatar Jan 08 '16 18:01 rowanmiller

/cc @saurabh500 @YoungGah @corivera

joshfree avatar Jan 08 '16 18:01 joshfree

cc'ing several customers who have reported this issue so that they can track the issue here and provide more details if needed

@dan-dragan @JohnBicknell @juswes

rowanmiller avatar Jan 08 '16 18:01 rowanmiller

any progress regarding SQL Client: Unable to load sni.dll (DllNotFoundException) issue?

taufiqueahmad avatar Jan 11 '16 08:01 taufiqueahmad

I too am getting this issue, on both RC1-update1 and on the RC2 nightly builds.

michael-jenkinson avatar Jan 11 '16 16:01 michael-jenkinson

@rowanmiller Do you mind to check whether you have that SNI.dll in this folder (as per error message) ? C:\Users\ddragan.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23616\runtimes\win7-x64\native\

Do you have instruction to repro this ?

kkurni avatar Jan 12 '16 02:01 kkurni

I got the same exception even if the app was working a few weeks ago. And the SNI.dll is present in the folder.

"System.DllNotFoundException: Unable to load DLL 'C:\Users\xxxx.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23516\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) "

matthieugd avatar Jan 12 '16 14:01 matthieugd

having same issue.

{"Unable to load DLL 'C...\\packages\\runtime.win7-x86.System.Data.SqlClient.sni\\4.0.0-beta-23516\\runtimes\\win7-x86\\native\\sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}

Any news on when fix is expected?

dlebedynskyi avatar Jan 12 '16 16:01 dlebedynskyi

Same here!

image

airomero avatar Jan 12 '16 16:01 airomero

I still trying to repro this. And try to find a clue what may cause this.

Please provide us with more information variation as possible to get this fix quickly.

how you repro this? Are you using dnx or corefx? What windows version? When this start happening? Did you recently pull the latest version, Did you get error on different version as well? Do you mind to share your snippet of code? are you calling EF or sqlclient?

kkurni avatar Jan 12 '16 16:01 kkurni

@joshfree @stephentoub This could potentially be packaging issue. Do you mind to ask packaging team to look into this issue as well?

kkurni avatar Jan 12 '16 16:01 kkurni

Heres is an example, it only happens using netcore x86 and x64 (1.0.0-rc1-update1)

image

In my case os : win7x64 ultimate (in win 10 it works fine)

airomero avatar Jan 12 '16 17:01 airomero

@kturni

how you repro this? Make a simple sql query using sqlclient and CoreClr x86 or x64 RC1 or (so far) nightly build. For most setups the work-around fix of installing Microsoft Visual C++ 2012 Redistributable worked. Where I'm stuck is deployment on IIS, which is via HttpPlatformHandler Module of IIS. On a windows 2008 R2 server (with C++ Redistributable installed) the application will run and query sql server fine from the command line using dnx web. Running via IIS, same dnx, SNI error returns, app starts up fine, just errors with SNI when you hit code that has a SQLClient query.

Are you using dnx or corefx? 1.0.0-rc1-update1 coreclr x64 win core64

What windows version? For me Windows 7 or Windows Server 2008 R2 (Works fine OSX)

When this start happening? Did you recently pull the latest version, Only started trying to get it working on windows last week.

Did you get error on different version as well? See above

Do you mind to share your snippet of code? are you calling EF or sqlclient? Just the simplest query using SQLConnection and SQLCommand will trigger it, no EF required.

JohnBicknell avatar Jan 12 '16 17:01 JohnBicknell

Thanks @JohnBicknell & @airomero.

So if I can summarize this issue, This issue only exist if you run this SQLClient code inside _IIS & Win2008R2/Win7_

_Does anyone has the same error, if run this Outside IIS ?_

@airomero does this work fine when you run it inside Windows 10 IIS ?

FYI, OSX/ unix will works as it will use managed SNI. only windows we use native SNI at this moment.

kkurni avatar Jan 12 '16 17:01 kkurni

I have the same problem on Windows 10 on IIS Express with coreclr-1.0.0-rc1-update1 x64 using EF

_dbContext.MyEntity.FirstOrDefault(x => x.Id == Guid.Empty);

System.DllNotFoundException: Unable to load DLL 'C:\Users\zzzz.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23516\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.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted) at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token) at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent() at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at Microsoft.Data.Entity.Storage.RelationalConnection.Open() at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext() at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source) at lambda_method(Closure , QueryContext ) at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_11.<CompileQuery>b__1(QueryContext qc) at Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 source, Expression`1 predicate)

matthieugd avatar Jan 12 '16 18:01 matthieugd

@kkurni Does anyone has the same error if your run this Outside IIS ? Just to be clear, I was getting it on Windows 7 and Windows Server 2008 R2, until installing Microsoft Visual C++ 2012 Redistributable. That just left IIS scenario not working.

JohnBicknell avatar Jan 12 '16 18:01 JohnBicknell

Thanks @JohnBicknell for your clarification.

It seems installing C++2012 will solve this https://github.com/dotnet/corefx/issues/3760.

Did you get the same error before you installed C++2012 outside IIS ?

kkurni avatar Jan 12 '16 18:01 kkurni

For me it is Working on windows 10 development machine but when i published on win server 2012 R2 it is not working, I installed Microsoft Visual C++ 2012 Redistributable as well but still getting same error.

System.DllNotFoundException: Unable to load DLL 'C:\Users\xxxxxx.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23516\runtimes\win7-x64\native\sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at

taufiqueahmad avatar Jan 12 '16 18:01 taufiqueahmad

Sorry i want to correct one thing, After published on Windows Server 2008 R2 is not working.

taufiqueahmad avatar Jan 12 '16 19:01 taufiqueahmad

@taufiqueahmad did you published to IIS ?

kkurni avatar Jan 12 '16 19:01 kkurni

In win7x64 not working even debugging in VS. Visual C++ 2012 Redistributable x86 and x64 are both installed.

airomero avatar Jan 12 '16 19:01 airomero