locked
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception RRS feed

  • Question

  • User448619955 posted

    Hi

    I'm using EntityFrameworkCore (3.1.3) with NteStandardLibrary (2.0.3)  and also in my web-api I'm using .Net Framework 4.7.2.

    when I run my application in my local computer I can connect to database and everythig seems fine.

    but when I publish it on server, I get following errors:

    {
    "key": "internalError",
    "message": "Internal server-error",
    "additionalInformation": "System.TypeInitializationException: The type initializer for
    'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception:
    Failed to load D:\\Data\\Customers\\bin\\x64\\SNI.dll\r\n
    at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() in
    E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\Interop\\
    SNINativeMethodWrapper.cs:line 66\r\n --- End of inner exception stack trace ---\r\n
    at Microsoft.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted
    (IntPtr token, Boolean& isRestricted)\r\n at Microsoft.Data.Win32NativeMethods.IsTokenRestrictedWrapper
    (IntPtr token) in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\
    Data\\Interop\\SNINativeMethodWrapper.cs:line 888\r\n at Microsoft.Data.ProviderBase.
    DbConnectionPoolIdentity.GetCurrent() in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\
    netfx\\src\\Microsoft\\Data\\ProviderBase\\DbConnectionPoolIdentity.cs:line 107\r\n
    at Microsoft.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
    in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\ProviderBase\\
    DbConnectionPoolGroup.cs:line 173\r\n at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPool
    (DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) in E:\\agn\\_task\\34\\s\\src\\
    Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\ProviderBase\\DbConnectionFactory.cs:line 364\r\n
    at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,
    TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection,
    DbConnectionInternal& connection) in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\
    Microsoft\\Data\\ProviderBase\\DbConnectionFactory.cs:line 205\r\n at
    Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,
    DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
    in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\ProviderBase\\
    DbConnectionInternal.cs:line 683\r\n at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1
    retry) in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\
    SqlClient\\SqlConnection.cs:line 1618\r\n at Microsoft.Data.SqlClient.SqlConnection.TryOpen
    (TaskCompletionSource`1 retry) in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\
    Microsoft\\Data\\SqlClient\\SqlConnection.cs:line 1599\r\n at Microsoft.Data.SqlClient.SqlConnection.
    OpenAsync(CancellationToken cancellationToken) in E:\\agn\\_task\\34\\s\\src\\Microsoft.Data.SqlClient
    \\netfx\\src\\Microsoft\\Data\\SqlClient\\SqlConnection.cs:line 1473\r\n--- End of stack trace from previous
    location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    \r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.<OpenDbConnectionAsync>d__50.MoveNext()\r\n--- End
    of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.
    ExceptionDispatchInfo.Throw()\r\n at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.
    <OpenDbConnectionAsync>d__50.MoveNext()\r\n--- End of stack trace from previous location where exception was
    thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.<OpenAsync>d__47.MoveNext()\r\n--- End of
    stack trace from previous location where exception was thrown ---\r\n at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__17.MoveNext()\r\n---
    End of stack trace from previous location where exception was thrown ---\r\n
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.<InitializeReaderAsync>d
    __18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.EntityFrameworkCore.SqlServer.
    Storage.Internal.SqlServerExecutionStrategy.<ExecuteAsync>d__7`2.MoveNext()\r\n--- End of
    stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.
    ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.
    HandleNonSuccessAndDebuggerNotification(Task task)\r\n
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.<MoveNextAsync>d__17.MoveNext()
    \r\n--- End of stack trace from previous location where exception was thrown ---\r\n
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
    at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__64`1.MoveNext()\r\n---
    End of stack trace from previous location where exception was thrown ---\r\n
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
    at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__64`1.MoveNext()\r\n---
    End of stack trace from previous location where exception was thrown ---\r\n
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices
    .TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
    System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at appweb.Controllers.
    TemplateController.<GetTemplates>d__5.MoveNext() in
    C:\\Projects\\myapp\\appweb\\Controllers\\TemplateController.cs:line 57",
    "identifierInformation": null,
    "statusCode": 500
    }

    I should mention that I've check both x64 and x86 folder in my server and both exists.

    Thanks.

    Thursday, July 23, 2020 6:45 AM

All replies