c# – 无法加载类型’System.Net.Security.SslStream’

前端之家收集整理的这篇文章主要介绍了c# – 无法加载类型’System.Net.Security.SslStream’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个简单的C#程序:
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();
    }
  }
}

我用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

当我执行时,抛出一个错误

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,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

我的Npgsql.dll版本

$monop2 -r Npgsql.dll 

Assembly Information:
Npgsql
Version=2.2.0.0
Culture=neutral
PublicKeyToken=5d8b90d52f46fda7

我的编译器:

$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

最后,我的环境:

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

谢谢

解决方法

我有一个问题 – 你在bin文件夹中有库Mono.Security.dll吗?如果是,请删除它并重试.
原文链接:https://www.f2er.com/csharp/101070.html

猜你在找的C#相关文章