-
Notifications
You must be signed in to change notification settings - Fork 305
Entity Framework Core 3.1.0 System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception #361
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
Comments
Hi @dmuruges Please add additional reference for Microsoft.Data.SqlClient 1.1.0 driver in your application and try again. Also ensure you have C++ Runtime installed and Nuget.exe version is > 5.0. There are similar issues in this repo where you can find relevant information. |
Thank you @cheenamalhotra. This futher explanation if for those people who might face the same issue in the future. I got this issue when I was using creating projects targetting .NET Framework 4.7.2 projects and try to use Entity Framework Core 3.1.0. (
SamuraiApp.Data was already having Microsoft.Data.SqlClient 1.0.9 and updated to Microsoft.Data.SqlClient 1.1.0 driver. The issue still remained. After installing Microsoft.Data.SqlClient 1.1.0 on the Console Application, the issue got resolved and the "update-database" command succeeded. Once again Thank you @cheenamalhotra. |
But which runtime on Win2008R2 ? Thanks |
With Microsoft.Data.SqlClient.SNI v1.1.1 we have removed dependency on VC Runtime, so you don't need that installed on your client if you reference this package with Microsoft.Data.SqlClient v1.1.1. |
Added a reference to Microsoft.Data.SqlClient to AppConfigDemo as described here: dotnet/SqlClient#361 (comment).
I am using VS2019 community edition. I am using the .NET Framework 4.7.2. I am having Samurai.domain .NETFramework class library project with 3 domain classes and Samurai.Data project with SamuraiContext. I am using Entity Framework Core 3.1.0 and SQLServer provider. A .NETFramework 4.7.2 Console application. Build was successful. Was able to create a migration in Samurai.Data project.
But I am getting error when I try to update the database. Please help.
PM> update-database
Build started...
Build succeeded.
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception: Failed to load E:\Projects\EFCore2\SamuraiApp\SomeUI\bin\Debug\x64\SNI.dll
at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() in E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 66
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
at Microsoft.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token) in E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 888
at Microsoft.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent() in E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.cs:line 107
at Microsoft.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory) in E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPoolGroup.cs:line 173
at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) in E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 364
at 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:line 205 at 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:line 683at 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:line 1618 at 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:line 1599at Microsoft.Data.SqlClient.SqlConnection.Open() in E:\agent1_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1250
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0
2.<Execute>b__0(DbContext c, TState s) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func
3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func
2 operation, Func`2 verifySucceeded)at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception.
The text was updated successfully, but these errors were encountered: