Efcore: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl' when scaffolding dbcontext

Created on 27 Oct 2016  路  11Comments  路  Source: dotnet/efcore

Steps to reproduce

I had followed instructions in https://www.microsoft.com/net/core#macos and was able to create and compile dot net core project with dotnet new and dotnet restore.

However, when I try to run dbcontext scaffolding with the following command

dotnet ef dbcontext scaffold "data source=xxx;initial catalog=xxx;persist security info=True;user id=xxx;password=x;MultipleAxxctiveResultSets=True;App=EntityFramework" "Microsoft.EntityFrameworkCore.SqlServer"

The error message appears

One or more errors occurred. (A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught))

After further digging, I found the most inner exception message says:

System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found.

Further technical details

EF Core version: "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
Operating system: Max OSX 10.11.3

closed-question

Most helpful comment

I installed dot core 1.1 preview from here and changed the version of "Microsoft.NETCore.App" to 1.1.0-preview1-001100-00 and everything worked fine.

I think it is some kind of version mismatch right? If one of my dot net core package dependency (in this case, "Microsoft.EntityFrameworkCore.SqlServer" is 1.1.* so should my "Microsoft.NETCore.App" be. Is that how dot net core worked out?

All 11 comments

Can you show your entire project.json

@davidfowl there you go

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        },
        "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0-preview1-final",
        "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0-preview1-final"
      },
      "imports": "dnxcore50"
    }
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  }
}

I have the exact same issue on my mac. SSL is installed ad linked ad described here: https://www.microsoft.com/net/core#macos

Full error message:

Connection id "0HKVUTKKMSK13": An unhandled exception was thrown by the application. System.Data.SqlClient.SqlException: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.TypeInitializationException: The type initializer for 'SslMethods' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Ssl' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SslInitializer' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Interop.CryptoInitializer.EnsureOpenSslInitialized() at Interop.CryptoInitializer..cctor() --- End of inner exception stack trace --- at Interop.CryptoInitializer.Initialize() at Interop.SslInitializer..cctor() --- End of inner exception stack trace --- at Interop.SslInitializer.Initialize() at Interop.Ssl..cctor() --- End of inner exception stack trace --- at Interop.Ssl.TlsV1Method() at Interop.Ssl.SslMethods..cctor() --- End of inner exception stack trace --- at Interop.OpenSsl.GetSslMethod(SslProtocols protocols) at Interop.OpenSsl.AllocateSslContext(SslProtocols protocols, SafeX509Handle certHandle, SafeEvpPKeyHandle certKeyHandle, EncryptionPolicy policy, Boolean isServer, Boolean remoteCertRequired) at System.Net.Security.SafeDeleteSslContext..ctor(SafeFreeSslCredentials credential, Boolean isServer, Boolean remoteCertRequired) at System.Net.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteContext& context, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, Boolean isServer, Boolean remoteCertRequired) --- End of inner exception stack trace --- at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslStream.BeginAuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation, AsyncCallback asyncCallback, Object asyncState) at System.Net.Security.SslStream.BeginAuthenticateAsClient(String targetHost, AsyncCallback asyncCallback, Object asyncState) at System.Threading.Tasks.TaskFactory``1.FromAsyncImpl[TArg1](Func``4 beginMethod, Func``2 endFunction, Action``1 endAction, TArg1 arg1, Object state, TaskCreationOptions creationOptions) at System.Net.Security.SslStream.AuthenticateAsClientAsync(String targetHost) at System.Data.SqlClient.SNI.SNITCPHandle.EnableSsl(UInt32 options) --- End of inner exception stack trace --- at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource``1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource``1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource``1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource``1 retry) at System.Data.SqlClient.SqlConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open() at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer) at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func``2 operation, Func``2 verifySucceeded, TState state) at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3``1.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15``2.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor``1.EnumeratorExceptionInterceptor.MoveNext() at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable``1 source, Int32& length) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable``1 source) at SqlMan.Controllers.TableController.List(Int32 connectionId, String filter) in /Users/silmoelker/Programming/dotNet/SqlMan/webapi/SqlMan/Controllers/TableController.cs:line 30 at lambda_method(Closure , Object , Object[] ) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame``1.<RequestProcessingAsync>d__2.MoveNext()

Same things here. It works locally with a windows machine but not in a docker image FROM microsoft/dotnet:latest hosted in an EC2 with CENTOS

see error:
System.Data.SqlClient.SqlException","Message":"A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)","Source":"Core .Net SqlClient Data Provider","Errors":"0:System.Data.SqlClient.SqlError: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)","ClientConnectionId":"8c947661-05d8-48cb-9b72-dd4d36be0230","Class":"20","LineNumber":"0","Number":"0","Procedure":"","Server":"NOTVISIBLEVALUE","State":"0","Data":"0:System.Collections.DictionaryEntry0:System.Collections.DictionaryEntry0:System.Collections.DictionaryEntry0:System.Collections.DictionaryEntry0:System.Collections.DictionaryEntry","InnerException":"System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.TypeInitializationException: The type initializer for 'SslMethods' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Ssl' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SslInitializer' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found.\n (Exception from HRESULT: 0x8007007E)\n at Interop.CryptoInitializer.EnsureOpenSslInitialized()\n at Interop.CryptoInitializer..cctor()\n --- End of inner exception stack trace ---\n at Interop.CryptoInitializer.Initialize()\n at Interop.SslInitializer..cctor()\n --- End of inner exception stack trace ---\n at Interop.SslInitializer.Initialize()\n at Interop.Ssl..cctor()\n --- End of inner exception stack trace ---\n at Interop.Ssl.TlsV1Method()\n at Interop.Ssl.SslMethods..cctor()\n --- End of inner exception stack trace ---\n at Interop.OpenSsl.GetSslMethod(SslProtocols protocols)\n at Interop.OpenSsl.AllocateSslContext(SslProtocols protocols, SafeX509Handle certHandle, SafeEvpPKeyHandle certKeyHandle, EncryptionPolicy policy, Boolean isServer, Boolean remoteCertRequired)\n

I am trying several things without success for the moment.

In project.json I am using:
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0-preview1-final"
"Microsoft.EntityFrameworkCore": "1.1.0-preview1-final"

Does this only happen when running migrations? Or do you get the same exception if you run your application and try to open a connection to the database?

It only happens when I try to connect to the database.

@jhayotte just to clarify... you are seeing the exception from the app running (rather than using migrations)?

The symptoms seem to match https://github.com/dotnet/corefx/issues/12983 and that refers to some preinstall requirements from https://www.microsoft.com/net/core#macos, in particular the following steps to create symlinks:

ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

@jhayotte have you done that?

@lukefan6 @smoelker @jhayotte This seems eerily similar to https://github.com/dotnet/corefx/issues/12517, but I thought this was fixed prior to release.

If the fix is the same as before, you should be able to get things working by updating your Microsoft.NETCore.App dependency to 1.1.0-preview1-001100-00 to match your other 1.1.0-preview1 dependencies.

I installed dot core 1.1 preview from here and changed the version of "Microsoft.NETCore.App" to 1.1.0-preview1-001100-00 and everything worked fine.

I think it is some kind of version mismatch right? If one of my dot net core package dependency (in this case, "Microsoft.EntityFrameworkCore.SqlServer" is 1.1.* so should my "Microsoft.NETCore.App" be. Is that how dot net core worked out?

Hi @rowanmiller, my issue came from the fact that i was not working with the framework netcoreapp1.1... Thanks @halter73 for your input!
Thanks guys!

Was this page helpful?
0 / 5 - 0 ratings