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)
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=1 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)
@saurabh500 @corivera can you please take a look? Is it critical for 2.0?
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
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 that's expected till 2.0 moves out of preview.
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 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.