Failed to load type "System.Net.Security.SslStream"

I have a simple C # program:

using Npgsql; public class App { public static void Main(string[] args) { const string CONNECTION_STRING = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase"; using (var conn = new NpgsqlConnection(CONNECTION_STRING)) { conn.Open(); } } } 

and I will compile it with mono (mcs):

 mcs -target:exe -lib:bin -r:System.Data.dll -r:Npgsql.dll -r:System.dll -r:Mono.Security.dll -out:bin/ssl.exe src/App.cs 

when I execute, an error is thrown:

 Unhandled Exception: System.TypeLoadException: Could not load type 'System.Net.Security.SslStream' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. at Npgsql.NpgsqlConnector.Open () <0x4155f7f0 + 0x00115> in <filename unknown>:0 at Npgsql.NpgsqlConnectorPool.GetPooledConnector (Npgsql.NpgsqlConnection Connection) <0x4155c8d0 + 0x00a4f> in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Net.Security.SslStream' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. at Npgsql.NpgsqlConnector.Open () <0x4155f7f0 + 0x00115> in <filename unknown>:0 at Npgsql.NpgsqlConnectorPool.GetPooledConnector (Npgsql.NpgsqlConnection Connection) <0x4155c8d0 + 0x00a4f> in <filename unknown>:0 

My Npgsql.dll version

 $ monop2 -r Npgsql.dll Assembly Information: Npgsql Version=2.2.0.0 Culture=neutral PublicKeyToken=5d8b90d52f46fda7 

My compiler:

 $ mcs --version Mono C# compiler version 4.4.0.0 $ mono --version Mono JIT compiler version 4.4.0 (Stable 4.4.0.40/f8474c4 Mon Mar 28 12:22:29 UTC 2016) Copyright (`u`C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: amd64 Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: sgen 

Finally, my environment:

 $ uname --all Linux abe 4.5.0-1-ARCH #1 SMP PREEMPT Tue Mar 15 09:41:03 CET 2016 x86_64 GNU/Linux 

thanks

+6
source share
3 answers

I have one question: do you have the Mono.Security.dll library inside the bin folder? If so, delete it and try again.

+13
source

I would like to put this information for people who will receive different exceptions, such as myself, I had:

 System.TypeLoadException: Failure has occurred while loading a type. at Npgsql.NpgsqlConnector.Open () [0x0002b] in <filename unknown>:0 at Npgsql.NpgsqlConnectorPool.GetPooledConnector (Npgsql.NpgsqlConnection Connection) [0x0017e] in <filename unknown>:0 

on

 conn.Open(); 

but the PIKos solution works for me too.

I use:

 Mono JIT compiler version 4.4.0 (tarball Tue Jun 14 13:41:51 UTC 2016) Npgsql.dll version 2.1.0.0 
0
source

Having created @pikos answer, I found one of the assemblies in the nuget package that I use, sent it Mono.Security.dll . However, mono 4.4.1 moves some types from this assembly and probably also moves some of them. Since I did not have an explicit reference to Mono.Security , the assembly [x | ms] detected an indirect dependency using an incompatible assembly in my packages folder.

To solve this problem, without any other workarounds (for example, removing assemblies for each assembly), I simply added an explicit assembly reference for the Mono.Security system. This forced the use of version 4.4.1 in the GAC. Without using one of nuget, I lost the patch that prompted the nuget builder to enable its own Mono.Security, but now I'm fine. YMMV.

0
source

All Articles