OSX上的.NET(Mono):无法连接到MongoDB

时间:2017-01-29 03:41:21

标签: c# mongodb macos mono

我正在使用Visual Studio for Mac开发一个安静的服务。为了连接到我的本地MongoDB实例(启动并运行),我安装了MongoDB NuGet包。类被正确引用到代码中,但是一旦我尝试执行连接,它就会响应以下错误:

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "An error occurred when trying to create a controller of type 'BalanzaController'. Make sure that the controller has a parameterless public constructor.",
  "ExceptionType": "System.InvalidOperationException",
  "StackTrace": "  at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create (System.Net.Http.HttpRequestMessage request, System.Web.Http.Controllers.HttpControllerDescriptor controllerDescriptor, System.Type controllerType) [0x000f3] in <f99f496cb0d249c1a945c1fcabce1695>:0 \n  at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController (System.Net.Http.HttpRequestMessage request) [0x00028] in <f99f496cb0d249c1a945c1fcabce1695>:0 \n  at System.Web.Http.Dispatcher.HttpControllerDispatcher+<SendAsync>d__1.MoveNext () [0x000a9] in <f99f496cb0d249c1a945c1fcabce1695>:0 ",
  "InnerException": {
      "Message": "An error has occurred.",
      "ExceptionMessage": "ntdll.dll",
      "ExceptionType": "System.DllNotFoundException",
      "StackTrace": "  at (wrapper managed-to-native) Interop+NtDll:RtlGetVersion (Interop/NtDll/RTL_OSVERSIONINFOEX&)\n  at Interop+NtDll.RtlGetVersion () [0x0001a] in <f13660f89d0d419fba4e315693dd26ea>:0 \n  at System.Runtime.InteropServices.RuntimeInformation.get_OSDescription () [0x00007] in <f13660f89d0d419fba4e315693dd26ea>:0 \n  at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument () [0x00042] in <2c531fdd26874b5eb450bd126d409101>:0 \n  at System.Lazy`1[T].CreateValue () [0x00075] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/Lazy.cs:437 "
  }
}

它以某种方式无法找到正确的dll文件(或其在Mono环境中的通讯员)。

我该如何解决?

由于

1 个答案:

答案 0 :(得分:1)

我使用Mono JIT编译器版本4.6.2在Raspberry PI 3(ARMV7)上得到了完全相同的异常。 将MongoDB C#驱动程序从2.4.X降级到2.3.0解决了我的问题。

此处还有一个未解决的问题: https://jira.mongodb.org/browse/CSHARP-1875