I have a desktop winforms application, which uses entity framework core to work with a SQL Server database.
During the debugging cycle the application runs without problem, makes the connections correctly and executes the queries correctly. When publishing the .exe application, and putting it on the end customer's computer, it fails.
Attached small project to reproduce the error. Download
Attached animated git with evidence. Download
Attention: The problem does not occur on the developer machine with Visual Studio. The problem occurs on the end customer's computer.
``C#
System.TypeInitializationException: Se produjo una excepci贸n en el inicializador de tipo de 'Microsoft.Data.SqlClient.TdsParser'. ---> System.TypeInitializationException: Se produjo una excepci贸n en el inicializador de tipo de 'Microsoft.Data.SqlClient.SNILoadHandle'. ---> System.TypeInitializationException: Se produjo una excepci贸n en el inicializador de tipo de 'Microsoft.Data.SqlClient.SNINativeMethodWrapper'. ---> System.ComponentModel.Win32Exception: Failed to load C:\Pruebas\Release\x86\SNI.dll
en Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:l铆nea 64
--- Fin del seguimiento de la pila de la excepci贸n interna ---
en Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()
en Microsoft.Data.SqlClient.SNILoadHandle..ctor() en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:l铆nea 31
en Microsoft.Data.SqlClient.SNILoadHandle..cctor() en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:l铆nea 16
--- Fin del seguimiento de la pila de la excepci贸n interna ---
en Microsoft.Data.SqlClient.TdsParser..cctor() en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:l铆nea 156
--- Fin del seguimiento de la pila de la excepci贸n interna ---
en Microsoft.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:l铆nea 32
en Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:l铆nea 1546
en Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:l铆nea 1442
en 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) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:l铆nea 425
en Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnectionFactory.cs:l铆nea 121
en Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:l铆nea 143
en Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:l铆nea 870
en Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:l铆nea 1807
en Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:l铆nea 1293
en Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) en E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:l铆nea 1191
en Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:l铆nea 302
en Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) en E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:l铆nea 683
en Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionClosed.cs:l铆nea 65
en Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) en E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:l铆nea 1605
en Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:l铆nea 1599
en Microsoft.Data.SqlClient.SqlConnection.Open() en E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:l铆nea 1250
en Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
en Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
en Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
en Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.InitializeReader(DbContext _, Boolean result)
en Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteTState,TResult
en Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext()
en System.Collections.Generic.List1..ctor(IEnumerable1 collection)
en System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
en WinAppEFCore.Form1.button1_Click(Object sender, EventArgs e) en F:\CODFT\WinAppEFCore\WinAppEFCore\Form1.cs:l铆nea 22
en System.Windows.Forms.Control.OnClick(EventArgs e)
en System.Windows.Forms.Button.OnClick(EventArgs e)
en System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
en System.Windows.Forms.Control.WndProc(Message& m)
en System.Windows.Forms.ButtonBase.WndProc(Message& m)
en System.Windows.Forms.Button.WndProc(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
en System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
```
Please help. I have stopped the entire publication of a new version of our product.
@ajcvickers @cheenamalhotra @roji @bricelam
EF Core version: 3.1.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Framework 4.6.1
Operating system:
Windows 10 Pro, Visual Studio 2019 16.5.0
looks related to https://github.com/dotnet/SqlClient/issues/385
looks related to dotnet/SqlClient#385
Hi, thanks, But my case is with a WinForms desktop application with destination .NET Framework 4.6.1. If you look at the code I attached for testing, it is something very small and normal, and it presents the problem.
Hi @ajcvickers ,
I did the review and testing:
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception: Failed to load C:\AppTest\Release\x86\SNI.dll
I think the problem has to do with something that you already worked on here
It has some similarity but I do not see clarity of how it was solved.
@estyfen It's probably related to or a duplicate of one the issues in the SqlClient repo I wanted to make sure you were running on a supported platform before directing you there.
@cheenamalhotra Does this look like a duplicate to you? If not it probably belongs in SqlClient.
@ajcvickers Thanks for your answer. I am going to do the review of open problems in sql repo.
Attention: The problem does not occur on the developer machine with Visual Studio. The problem occurs on the end customer's computer.
It maybe due to missing VC++ runtime on customer's machine. Could you try referencing package "Microsoft.Data.SqlClient.SNI:v1.1.1" directly in your project along with Microsoft.Data.SqlClient:1.1.1 as that removes dependency on VC++ Runtime.
Attention: The problem does not occur on the developer machine with Visual Studio. The problem occurs on the end customer's computer.
It maybe due to missing VC++ runtime on customer's machine. Could you try referencing package "Microsoft.Data.SqlClient.SNI:v1.1.1" directly in your project along with Microsoft.Data.SqlClient:1.1.1 as that removes dependency on VC++ Runtime.
@cheenamalhotra @ajcvickers I could already solve it with your recommendation.
A thousand thanks for giving me back my life. You are a blessing to the community . Until next time!! :)
Most helpful comment
It maybe due to missing VC++ runtime on customer's machine. Could you try referencing package "Microsoft.Data.SqlClient.SNI:v1.1.1" directly in your project along with Microsoft.Data.SqlClient:1.1.1 as that removes dependency on VC++ Runtime.