runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.Data.SqlClient .NET Core 2.0 Preview 2 - Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Open a688 opened this issue 9 years ago • 6 comments

I'm getting this error with .NET core 2.0 Preview 2. I'm running Windows 7 SP1 x64. When I run dotnot --version from my output directory I get 2.0.0-preview2-006497

Code Example:

        static void Main(string[] args)
        {
            using (var conn = new System.Data.SqlClient.SqlConnection(<your own connection string>)) {
                using (var cmd = new System.Data.SqlClient.SqlCommand(<your own sql text>, conn)) {
                    cmd.CommandType = System.Data.CommandType.Text;

                    conn.Open();   // error happens here
                    var reader = cmd.ExecuteReader();

                    while (reader.Read()) {
                        // doesn't matter
                    }
                }
            }

            System.Console.WriteLine("Done");
        }

Repo steps using VS 15.3.0 Preview 3.0:

Create new C# .NET Core console app Add System.Data.SqlClient from nuget (currently version 4.3.1) Copy/paste code from above Start debugging project

What should happen:

It should just work. It works fine in a project that targets "regular" .NET

Exception I'm getting:

System.TypeInitializationException occurred HResult=0x80131534 Message=The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. Source= StackTrace: at System.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 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.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at ConsoleApp1.Program.Main(String[] args) in C:\Users\joshua_lonberger\Desktop\TicketModeler\ConsoleApp1\Program.cs:line 17

Inner Exception 1: TypeInitializationException: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception.

Inner Exception 2: DllNotFoundException: Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

a688 avatar Jun 30 '17 12:06 a688

@saurabh500 @corivera can you please take a look? Is it critical for 2.0?

karelz avatar Jun 30 '17 13:06 karelz

Try using SqlClient 4.4.0 preview version. I will try a repro today. @karelz let us look into the issue to figure out the impact. If it's not an app config issue then sqlclient is unusable on windows

saurabh500 avatar Jun 30 '17 16:06 saurabh500

It works when I update to the 4.4 preview (4.4.0-preview2-25405-01 to be exact). Should that (having to use prereleases) be expected when adding packages while .net core 2.0 is still in preview?

a688 avatar Jun 30 '17 17:06 a688

@a688 that's expected till 2.0 moves out of preview.

saurabh500 avatar Jun 30 '17 17:06 saurabh500

I've a web job and its getting the same exception, but I am not using Microsoft.AspNetCore.All. Using netcoreapp2.1 and runtimeIdentifiers are win10-x64;osx.10.11-x64 Any idea?

joseclament avatar Jun 06 '18 08:06 joseclament

@joseclament please do not cross-post, especially not on closed issues. If you have a problem, create isolated repro, put together current behavior description vs. expected and file a new issue. The description you provide above does not seem to be sufficient.

karelz avatar Jun 06 '18 15:06 karelz