Npgsql.NpgsqlConnection 没有实现接口 System.Collections.IEnumerator

Npgsql.NpgsqlConnection doesn't implement interface System.Collections.IEnumerator

在 Visual Studio 中,我创建了简单的 vNext 控制台应用程序并使用

安装了 Npgsql
Install-Package Npgsql 

命令。

这是代码,Program.cs和project.json

using Npgsql;
using System;

namespace ConsoleApp3
{
public class Program
{
    public void Main(string[] args)
    {
        Console.WriteLine("Hello postgresql!");
        // Specify connection options and open an connection
        NpgsqlConnection conn = new NpgsqlConnection("Server=myserv;User Id=postgres;" +
                                "Password=postgres;Database=mydb;");
        conn.Open();

        // Define a query
        NpgsqlCommand cmd = new NpgsqlCommand("select name from mytb", conn);

        // Execute a query
        NpgsqlDataReader dr = cmd.ExecuteReader();

        // Read all rows and output the first column in each row
        while (dr.Read())
            Console.Write("{0}\n", dr[0]);

        // Close connection
        conn.Close();
        Console.ReadLine();
    }
}
}


{
"version": "1.0.0-*",
"dependencies": {
    "Npgsql": "2.2.4.3",
    "System.Data.Common": "4.0.0-beta-22605"

},
"commands": {
    "ConsoleApp3": "run"
},
"frameworks": {
    "aspnet50": {
        "frameworkAssemblies": {
            "System.Data": "4.0.0.0"
        }
    }        
}

}

一切正常。

然后我在装有 Mono 和 Debian 的机器上复制了这段代码 OS。

mono --version

Mono JIT compiler version 3.12.1 (tarball Fri Mar  6 19:12:47 UTC 2015)
Copyright (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

然后我做了

kpm restore

k run

我遇到了异常:

Hello postgresql!
Npgsql.NpgsqlConnection doesn't implement interface     System.Collections.IEnumerator
Stacktrace:
at <unknown> <0xffffffff>
at ConsoleApp3.Program.Main (string[]) <0x0004c>  
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>  
at <unknown> <0xffffffff>  
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>  
at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>  
at System.Reflection.MethodBase.Invoke (object,object[]) <0x0002a>
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute (System.Reflection.Assembly,string[],System.IServiceProvider) <0x0010b>  
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain (Microsoft.Framework.Runtime.DefaultHost,string,string[]) <0x0026f>  
at Microsoft.Framework.ApplicationHost.Program.Main (string[]) <0x0043f>  
at (wrapper runtime-invoke) <Module>.runtime_invoke_object__this___object (object,intptr,intptr,intptr) <0xffffffff>  
at <unknown> <0xffffffff>  
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>  
at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>  
at System.Reflection.MethodBase.Invoke (object,object[]) <0x0002a>
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute (System.Reflection.Assembly,string[],System.IServiceProvider) <0x0010b>  
at kre.host.Bootstrapper.Main (string[]) <0x002f3>
at (wrapper runtime-invoke) <Module>.runtime_invoke_object__this___object (object,intptr,intptr,intptr) <0xffffffff>
at <unknown> <0xffffffff>  
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>  
at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>  
at System.Reflection.MethodBase.Invoke (object,object[]) <0x0002a>  
at kre.hosting.RuntimeBootstrapper.ExecuteAsync (string[]) <0x01667>  
at kre.hosting.RuntimeBootstrapper.Execute (string[]) <0x00053>  
at EntryPoint.Main (string[]) <0x00167>  
at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:
mono() [0x4accac]   
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf0a0) [0x7f03a02c60a0] 
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x35) [0x7f039ff5e165]  
/lib/x86_64-linux-gnu/libc.so.6(abort+0x180) [0x7f039ff613e0]   
mono() [0x6232f9]   
mono() [0x623507]   
mono() [0x6235b2]   
mono() [0x4aebe7]   
mono() [0x4af3c3]   
[0x40ef3de6]

Debug info from gdb:

=================================================================
Got a SIGABRT while executing native code. 
This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Aborted

有人知道如何处理吗?

问题出在存储在 Mono GAC 中的旧版本 Npgsql.dll 中。引导加载程序使用这个旧的二进制文件,而不是来自 NuGet 包的全新 Npgsql.dll。