Skip to content
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

Mono: System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.InOutOfProcHelper' #1263

Open
lillo42 opened this issue Sep 13, 2021 · 17 comments

Comments

@lillo42
Copy link

lillo42 commented Sep 13, 2021

Error to connect on SQL Server using Microsoft.Data.SqlClient with Mono on linux.

Exception message: The type initializer for 'Microsoft.Data.SqlClient.InOutOfProcHelper' threw an exception. 
Stack trace:
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.InOutOfProcHelper' threw an exception. ---> System.EntryPointNotFoundException: GetModuleHandle assembly:<unknown assembly> type:<unknown type> member:(null)

  at (wrapper managed-to-native) Microsoft.Data.Common.SafeNativeMethods.GetModuleHandle(string)

  at Microsoft.Data.SqlClient.InOutOfProcHelper..ctor () [0x00006] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.SqlClient.InOutOfProcHelper..cctor () [0x00000] in <de6019a43b5544ecb987a2a77d294ad3>:0 

   --- End of inner exception stack trace ---

  at Microsoft.Data.SqlClient.SqlConnectionString..ctor (System.String connectionString) [0x0000d] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions (System.String connectionString, Microsoft.Data.Common.DbConnectionOptions previous) [0x00000] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup (Microsoft.Data.Common.DbConnectionPoolKey key, Microsoft.Data.ProviderBase.DbConnectionPoolGroupOptions poolOptions, Microsoft.Data.Common.DbConnectionOptions& userConnectionOptions) [0x0003e] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set (Microsoft.Data.Common.DbConnectionPoolKey key) [0x00008] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString (System.String value) [0x000c8] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.SqlClient.SqlConnection..ctor (System.String connectionString, Microsoft.Data.SqlClient.SqlCredential credential) [0x00006] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at Microsoft.Data.SqlClient.SqlConnection..ctor (System.String connectionString) [0x00000] in <de6019a43b5544ecb987a2a77d294ad3>:0 

  at (wrapper remoting-invoke-with-check) Microsoft.Data.SqlClient.SqlConnection..ctor(string)

  at MonoCrash.Program.Main (System.String[] args) [0x00002] in <b0c88f4fc5724b4fbf81cd0ce25f6959>:0 

To reproduce

Gist: https://gist.github.com/arhughes/8b15d7ee88da250cc4492814cac6db52

public static void Main(string[] args)
{
    try
    {
        using (var connection = new SqlConnection("Server=mssql;User Id=sa;Password=Password1!"))
        {
            connection.Open();
            Console.WriteLine("Connection opened successfully.");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}

Expected behavior

Connect to the database.

Further technical details

Microsoft.Data.SqlClient version: 3.0.0
.NET target: Mono with .NET Framework 4.7.1
SQL Server version: SQL Server 2017
Operating system: Docker container - Linux

Additional context

Reported: fluentmigrator/fluentmigrator#1483

@Wraith2
Copy link
Contributor

Wraith2 commented Sep 13, 2021

This is fixed in 4.0.0 preview with #1120 Can you give the preview a try and see if that resolves your issue please.

@JRahnama
Copy link
Member

@lillo42 thanks for bringing this up. As @Wraith2 mentioned we fixed this issue in our latest preview release 4.0.0-preview1.21237.2. Can you try and let us know if the issue is resolved please?

@lillo42
Copy link
Author

lillo42 commented Sep 13, 2021

I've update to 4.0.0-preview1.21237.2, but I'm getting this error:

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.DllNotFoundException: Microsoft.Data.SqlClient.SNI.x64.dll assembly:<unknown assembly> type:<unknown type> member:(null)

  at (wrapper managed-to-native) Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.SNIInitialize(bool,intptr)

  at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize (System.Boolean useSystemDefaultSecureProtocols, System.IntPtr pmo) [0x0000f] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize () [0x00005] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SNILoadHandle..ctor () [0x0003e] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SNILoadHandle..cctor () [0x00000] in <544c5008773d450c9a427a87ae3f3679>:0 

   --- End of inner exception stack trace ---

   --- End of inner exception stack trace ---

  at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (Microsoft.Data.SqlClient.ServerInfo serverInfo, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance, Microsoft.Data.SqlClient.SqlConnectionString connectionOptions, Microsoft.Data.SqlClient.SqlCredential credential, Microsoft.Data.ProviderBase.TimeoutTimer timeout) [0x0013c] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (Microsoft.Data.ProviderBase.TimeoutTimer timeout, Microsoft.Data.SqlClient.SqlConnectionString connectionOptions, Microsoft.Data.SqlClient.SqlCredential credential, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance) [0x000fa] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor (Microsoft.Data.ProviderBase.DbConnectionPoolIdentity identity, Microsoft.Data.SqlClient.SqlConnectionString connectionOptions, Microsoft.Data.SqlClient.SqlCredential credential, System.Object providerInfo, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance, Microsoft.Data.SqlClient.SqlConnectionString userConnectionOptions, Microsoft.Data.SqlClient.SessionData reconnectSessionData, Microsoft.Data.SqlClient.ServerCertificateValidationCallback serverCallback, Microsoft.Data.SqlClient.ClientCertificateRetrievalCallback clientCallback, Microsoft.Data.ProviderBase.DbConnectionPool pool, System.String accessToken, Microsoft.Data.SqlClient.SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, System.Boolean applyTransientFaultHandling) [0x00195] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection (Microsoft.Data.Common.DbConnectionOptions options, Microsoft.Data.Common.DbConnectionPoolKey poolKey, System.Object poolGroupProviderInfo, Microsoft.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningConnection, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x001aa] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection (System.Data.Common.DbConnection owningConnection, Microsoft.Data.ProviderBase.DbConnectionPoolGroup poolGroup, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x00015] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection (System.Data.Common.DbConnection owningConnection, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions, Microsoft.Data.ProviderBase.DbConnectionInternal oldConnection, Microsoft.Data.ProviderBase.DbConnectionInternal& connection) [0x001ca] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal (System.Data.Common.DbConnection outerConnection, Microsoft.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x00036] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection (System.Data.Common.DbConnection outerConnection, Microsoft.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x00000] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner (System.Threading.Tasks.TaskCompletionSource`1[TResult] retry) [0x00045] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlConnection.TryOpen (System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.SqlClient.SqlConnectionOverrides overrides) [0x00104] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlConnection.Open (Microsoft.Data.SqlClient.SqlConnectionOverrides overrides) [0x00072] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SqlConnection.Open () [0x00000] in <544c5008773d450c9a427a87ae3f3679>:0 

  at MonoCrash.Program.Main (System.String[] args) [0x0000e] in <0723bc6ac5c64a729e1f3049bad83ce9>:0 

[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Microsoft.Data.SqlClient.SNI.x64.dll assembly:<unknown assembly> type:<unknown type> member:(null)

  at (wrapper managed-to-native) Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.SNIInitialize(bool,intptr)

  at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize (System.Boolean useSystemDefaultSecureProtocols, System.IntPtr pmo) [0x0000f] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize () [0x00005] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SNILoadHandle..ctor () [0x0003e] in <544c5008773d450c9a427a87ae3f3679>:0 

  at Microsoft.Data.SqlClient.SNILoadHandle..cctor () [0x00000] in <544c5008773d450c9a427a87ae3f3679>:0 

   --- End of inner exception stack trace ---

@lillo42
Copy link
Author

lillo42 commented Sep 13, 2021

The code MonoCrash.zip

@0xced
Copy link
Contributor

0xced commented Sep 23, 2021

After upgrading to the v4 preview package, I tried again (see description in #1120). After disabling shadow copy to make sure that Microsoft.Data.SqlClient.SNI.x64.dll was found, I kept getting a DllNotFoundException:

System.DllNotFoundException : Microsoft.Data.SqlClient.SNI.x64.dll assembly: type: member:(null)

So I ran the tests again with mono debug logs: MONO_LOG_LEVEL=debug dotnet test --framework net472 […]. Then I spotted this:

Mono: DllImport attempting to load: 'Microsoft.Data.SqlClient.SNI.x64.dll'.
Mono: DllImport error loading library '~/Projects/DockerRunner/tests/SqlServer/bin/Debug/net472/Microsoft.Data.SqlClient.SNI.x64.dll': 'dlopen(~/Projects/DockerRunner/tests/SqlServer/bin/Debug/net472/Microsoft.Data.SqlClient.SNI.x64.dll, 9): no suitable image found.  Did find:
	~/Projects/DockerRunner/tests/SqlServer/bin/Debug/net472/Microsoft.Data.SqlClient.SNI.x64.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
	~/Projects/DockerRunner/tests/SqlServer/bin/Debug/net472/Microsoft.Data.SqlClient.SNI.x64.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00'.

Of course! The Microsoft.Data.SqlClient.SNI.x64.dll file is a Windows-only (PE32+) dll, there is no Linux nor macOS native SNI dll (.so/.dylib) so there is absolutely no way for SNI to work on those platforms.

Now the question is: why does the SNI initialization code path is triggered on Mono running Linux/macOS? I guess it's not triggered at all on .NET Core running Linux/macOS, am I right?

@Wraith2
Copy link
Contributor

Wraith2 commented Sep 23, 2021

Are you compiling against against a windows target and copying the files to a linux host? That's the only way I can think of that you'd get an implementation that tries to use the windows dlls on a linux system, the linux assemblies force managed sni.

@0xced
Copy link
Contributor

0xced commented Sep 23, 2021

I don't copy any files manually. Here's what I'm doing, i.e. running a unit test targeting net472 on macOS or Linux:

mono --version >/dev/null && echo "✅ mono is installed" || echo "❌ mono must be installed"
docker info >/dev/null && echo "✅ docker is running" || echo "❌ docker must be running"
git clone https://github.com/0xced/DockerRunner
cd DockerRunner
git checkout Microsoft.Data.SqlClient-v4
dotnet test --framework net472 --filter DisplayName~SqlServer2019Test tests/SqlServer/DockerRunner.Tests.SqlServer.csproj

And here are some relevant stack traces resulting from using Microsoft.Data.SqlClient on macOS under Mono.

---- 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.DllNotFoundException : Microsoft.Data.SqlClient.SNI.x64.dll assembly:<unknown assembly> type:<unknown type> member:(null)
--- End of stack trace from previous location where exception was thrown ---

  at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (Microsoft.Data.SqlClient.ServerInfo serverInfo, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance, Microsoft.Data.SqlClient.SqlConnectionString connectionOptions, Microsoft.Data.SqlClient.SqlCredential credential, Microsoft.Data.ProviderBase.TimeoutTimer timeout) [0x0013c] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (Microsoft.Data.ProviderBase.TimeoutTimer timeout, Microsoft.Data.SqlClient.SqlConnectionString connectionOptions, Microsoft.Data.SqlClient.SqlCredential credential, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance) [0x000fa] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor (Microsoft.Data.ProviderBase.DbConnectionPoolIdentity identity, Microsoft.Data.SqlClient.SqlConnectionString connectionOptions, Microsoft.Data.SqlClient.SqlCredential credential, System.Object providerInfo, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance, Microsoft.Data.SqlClient.SqlConnectionString userConnectionOptions, Microsoft.Data.SqlClient.SessionData reconnectSessionData, Microsoft.Data.SqlClient.ServerCertificateValidationCallback serverCallback, Microsoft.Data.SqlClient.ClientCertificateRetrievalCallback clientCallback, Microsoft.Data.ProviderBase.DbConnectionPool pool, System.String accessToken, Microsoft.Data.SqlClient.SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, System.Boolean applyTransientFaultHandling) [0x00195] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection (Microsoft.Data.Common.DbConnectionOptions options, Microsoft.Data.Common.DbConnectionPoolKey poolKey, System.Object poolGroupProviderInfo, Microsoft.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningConnection, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x001aa] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection (System.Data.Common.DbConnection owningConnection, Microsoft.Data.ProviderBase.DbConnectionPoolGroup poolGroup, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x00015] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.ProviderBase.DbConnectionFactory+<>c__DisplayClass31_0.<TryGetConnection>b__1 (System.Threading.Tasks.Task`1[TResult] _) [0x00020] in <7be59b55362e4015909477dd5db67609>:0 
----- Inner Stack Trace -----
  at (wrapper managed-to-native) Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.SNIInitialize(bool,intptr)
  at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize (System.Boolean useSystemDefaultSecureProtocols, System.IntPtr pmo) [0x0000f] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize () [0x00005] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.SqlClient.SNILoadHandle..ctor () [0x0003e] in <7be59b55362e4015909477dd5db67609>:0 
  at Microsoft.Data.SqlClient.SNILoadHandle..cctor () [0x00000] in <7be59b55362e4015909477dd5db67609>:0 

You can get the full stack traces in the TestResults-Linux file the that just ran on GitHub actions.

Note that running the same unit test on net5.0 fails with another error:

---- Microsoft.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 : The remote certificate was rejected by the provided RemoteCertificateValidationCallback.
  Stack Trace:
     at DockerRunner.Database.DockerDatabaseContainerRunner.StartAsync(DockerDatabaseContainerConfiguration configuration, EventHandler`1 runningCommand, EventHandler`1 ranCommand, EventHandler`1 sqlCommandExecuting, Boolean waitOnDispose, CancellationToken cancellationToken) in DockerRunner/src/DockerRunner/Database/DockerDatabaseContainerRunner.cs:line 91
   at DockerRunner.Database.DockerDatabaseContainerRunner.StartAsync(DockerDatabaseContainerConfiguration configuration, EventHandler`1 runningCommand, EventHandler`1 ranCommand, EventHandler`1 sqlCommandExecuting, Boolean waitOnDispose, CancellationToken cancellationToken) in DockerRunner/src/DockerRunner/Database/DockerDatabaseContainerRunner.cs:line 99
   at DockerRunner.Tests.DockerDatabaseContainerRunnerTest`1.StartDockerDatabaseContainer() in DockerRunner/tests/Base/DockerDatabaseContainerRunnerTest.cs:line 23
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.InternalOpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at DockerRunner.Database.DockerDatabaseContainerRunner.StartAsync(DockerDatabaseContainerConfiguration configuration, EventHandler`1 runningCommand, EventHandler`1 ranCommand, EventHandler`1 sqlCommandExecuting, Boolean waitOnDispose, CancellationToken cancellationToken) in DockerRunner/src/DockerRunner/Database/DockerDatabaseContainerRunner.cs:line 81
----- Inner Stack Trace -----
   at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)
   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
   at System.Net.Security.SslStream.ProcessAuthentication(Boolean isAsync, Boolean isApm, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
   at Microsoft.Data.SqlClient.SNI.SNITCPHandle.EnableSsl(UInt32 options)

@cheenamalhotra
Copy link
Member

--framework net472 will download .NET Framework DLL from Microsoft.Data.SqlClient NuGet package which is Windows only.

When using net5.0, please turn off Encrypt (set to false) as it's now enabled by default in Microsoft.Data.SqlClient to get past pre-login handshake error.

@Kaur-Parminder
Copy link
Contributor

Kaur-Parminder commented Sep 27, 2021

@lillo42 I was getting the exception as you mentioned for both version: 3.0.0 and 4.0.0 preview when I was not using the .net framework image along with Mono.

Here is the gist (Windows + .net472 +mono) that is using latest Microsoft.Data.SqlClient and is opening connection successfully.
https://gist.github.com/Kaur-Parminder/1cca8a1a7cd7f47520ed5e9b05d56456

@lillo42
Copy link
Author

lillo42 commented Sep 27, 2021

@Kaur-Parminder can you try to run using .NET Framework with mono on Linux?

@Kaur-Parminder
Copy link
Contributor

Here is one for Linux container with .netcore 3.1 and mono https://gist.github.com/Kaur-Parminder/92b92ef2152ba3dcbdb168e4983a1e2c

@lillo42
Copy link
Author

lillo42 commented Sep 27, 2021

@Kaur-Parminder in your last sample did you build the project using .NET Framework or .NET Core?
My problem is when I build target .NET Framework (4.7.2 or 4.8) and run it using Mono on Linux

@Kaur-Parminder
Copy link
Contributor

I have used .NetCore with Linux.
For .net472 with Linux Visual studio, It throws error Linux container are not supported for this project.
Are you using just mono image in your Dockerfile?

@lillo42
Copy link
Author

lillo42 commented Sep 28, 2021

@Kaur-Parminder
Copy link
Contributor

Kaur-Parminder commented Sep 28, 2021

@lillo42 I see the error when target is set to net 48 and net 471. Dlls seems are not being loaded correctly although they are present in the bin folder. I have not been able to find way to Debug the issue through VS docker-compose for Linux container (.netframeowrk projects is only debuggable with Windows container). We have to look into it further. I see System.Data and System.Data.Sqlclient are able to open connection successfully but not Microsoft.Data.SqlClient.

@cheenamalhotra cheenamalhotra added this to Needs triage in SqlClient Triage Board via automation Sep 29, 2021
@cheenamalhotra cheenamalhotra moved this from Needs triage to Under Investigation in SqlClient Triage Board Sep 29, 2021
@cheenamalhotra cheenamalhotra moved this from Under Investigation to Repro Available in SqlClient Triage Board Sep 30, 2021
@jzabroski
Copy link

@cheenamalhotra Any update here? There's a repro available and the recommended workaround seems to be to disable encryption, which seems unacceptable for some customers?

@Wraith2
Copy link
Contributor

Wraith2 commented May 5, 2022

The netfx implementation requires an unmanaged component to implement network connectivity. That implementaion is closed source non-portable and not provided for non-windows platforms. In the cases above people are restoring the netfx implementation and trying to use it on linux and that won't work. If you want to run the code on linux you need to use the correct platform implementation assembly.

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

No branches or pull requests

7 participants