Skip to content

.net framework using entityframeworkcore sni.dll missing #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
organiccomputer opened this issue Jan 9, 2020 · 12 comments
Closed

.net framework using entityframeworkcore sni.dll missing #373

organiccomputer opened this issue Jan 9, 2020 · 12 comments

Comments

@organiccomputer
Copy link

I'm working with a .net framework 4.7.2 application and I am using entityframeworkcore. When I try to access my database I receive the following stacktrace:

[Win32Exception (0x80004005): Failed to load C:\repo\bin\x86\SNI.dll]
   Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:64

[TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception.]
   Microsoft.Data.SqlClient.SNILoadHandle..ctor() in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:31
   Microsoft.Data.SqlClient.SNILoadHandle..cctor() in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:16

[TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.]
   Microsoft.Data.SqlClient.TdsParser..cctor() in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:156

[TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.]
   Microsoft.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:32
   Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:1546
   Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:1442
   Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, DbConnectionPool pool, String accessToken, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:425
   Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnectionFactory.cs:121
   Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:143
   Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:870
   Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:1807
   Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:1293
   Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:1191
   Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:302
   Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:683
   Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionClosed.cs:65
   Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:1605
   Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:1599
   Microsoft.Data.SqlClient.SqlConnection.Open() in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:1250
   Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) +358
   Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) +124
   Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) +154
   Microsoft.EntityFrameworkCore.Query.Internal.Enumerator.InitializeReader(DbContext _, Boolean result) +204
   Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute(TState state, Func`3 operation, Func`3 verifySucceeded) +57
   Microsoft.EntityFrameworkCore.Query.Internal.Enumerator.MoveNext() +550
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +186
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +54
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +85
   System.Web.UI.Control.OnLoad(EventArgs e) +79
   System.Web.UI.Control.LoadRecursive() +130
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2852```
@cheenamalhotra
Copy link
Member

Hi @organiccomputer

If this is WPF Application, that's a known issue, see my comment here: #137 (comment)
Otherwise ensure you are using latest driver, refer: #361 (comment)

@Hoaas
Copy link

Hoaas commented Jan 10, 2020

I am experiencing the same thing, but only on the test server. Locally everything works fine.

In my case there is a .NET Framework 4.7.2 project referencing a .netstandard2.0 project handing Entity Framework and data access. Have not previously referenced any SqlClients directly. I have tried installing Microsoft.Data.SqlClient 1.1.0 on both projects now without seeing any difference.

@organiccomputer
Copy link
Author

organiccomputer commented Jan 10, 2020

@cheenamalhotra, my application is actually web forms but the code using ef core is in a separate repository dll. I will also look into the comments you referenced.

@cheenamalhotra
Copy link
Member

cheenamalhotra commented Jan 10, 2020

@Hoaas

Could you try the repro from link below and confirm if it works in your test environment?
SqlClient Transitive Example

@michaelmairegger
Copy link

michaelmairegger commented Jan 13, 2020

@cheenamalhotra
I have similar issues but your sample works. Instead I have issues if I build a DesktopBridge WPF application. There in the .appxupload file the sni.dll file is missing

You can find my sample project with DesktopBridge sample here: https://github.com/michaelmairegger/SqlClientTransitive

This is the build folder of the Consumer Project
BuildFolder Consumer

This is the build folder of the DesktopBridge Project. Even though that in Consumer build output the x86 and x64 folder with the sni.dll is there, the folder with the content is missing in the DesktopBridge project.
BuildFolder DesktopBridge

@michaelmairegger
Copy link

For now the following Workaround works:

<ItemGroup>
    <None Include="$(USERPROFILE)\.nuget\packages\microsoft.data.sqlclient.sni\1.0.19235.1\buildTransitive\net46\x64\SNI.dll">
      <Link>x64\SNI.dll</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <None Include="$(USERPROFILE)\.nuget\packages\microsoft.data.sqlclient.sni\1.0.19235.1\buildTransitive\net46\x86\SNI.dll">
      <Link>x86\SNI.dll</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

@Hoaas
Copy link

Hoaas commented Jan 13, 2020

@cheenamalhotra
Built from my machine it works fine on the server. Haven't set up build and deploy from Azure DevOps. I suspect an older NuGet version might be in use. However many other services and websites built on the same server, all using Entity Framework, without any issues.

@organiccomputer
Copy link
Author

@cheenamalhotra, I was able to run the repro successfully. The best that I can come up with is that my class library is using microsoft.entityframeworkcore.sqlserver which uses Microsoft.Data.SqlClient version 1.0.19269.1 rather than 1.1.0.

@organiccomputer
Copy link
Author

@cheenamalhotra, I am also converting my class libraries to .net standard 2.0 rather than framework 4.7.2 to see if that helps.

@cheenamalhotra
Copy link
Member

cheenamalhotra commented Jan 13, 2020

@michaelmairegger

I agree on the issue with WPF .NET framework application transitive ref, I'm looking into it currently. Please continue with the workaround for now in that case or you can also switch to WPF .NET Core application which works fine.

@organiccomputer
It should also work with v1.0.19269.1 since the fix was released before this version in one of the previews. If you followed same steps and still face issues, please upload your repro so we can take a look too.

@organiccomputer
Copy link
Author

@cheenamalhotra, I'll begin working on that once I have finished testing a potential fix. Thank you.

@organiccomputer
Copy link
Author

@cheenamalhotra, I was able to resolve the issue by converting my class libraries to .net standard rather than framework 4.7.2. I'm going to close the ticket since my issue was resolved. However, I'm still not sure why it would pull in the sni.dll for .net standard and not for .net framework using the same version of microsoft.entityframeworkcore.sqlserver (3.1.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants