从azure函数连接到MongoDB

时间:2017-02-04 21:15:12

标签: c# mongodb azure azure-functions

我在使用microsoft azure上运行的C#函数连接到MongoDB时遇到问题。该函数是时间触发的,它应该从MongoDB收集一些数据并将它们放入存储队列。

我已将mongoDB依赖项添加到to project.json,这就是文件的样子:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "MongoDB.Bson": "2.4.2",
        "MongoDB.Driver": "2.4.2",
        "MongoDB.Driver.Core": "2.4.2",
        "System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
      }
    }
  }
}

然而,当我打电话时:

MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(conn));
settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
var client = new MongoClient(settings);

调用最后一行后出错:

mscorlib: Exception has been thrown by the target of an invocation. MongoDB.Driver.Core: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

我已经检查过.net版本是4.6所以应该没有问题。还有什么我想念的。

1 个答案:

答案 0 :(得分:5)

我一直在挖掘他们的JIRA问题并找到JIRA ISSUE。我已将MongoDB.Driver MongoDB.Driver.CoreMongoDB.Bson恢复为版本2.3.0,它的工作方式就像一个精细的手表,所以它似乎是Mongo包本身的问题

我已经使用不同版本的软件包对其进行了测试,问题在2.4.0版本中引入。所有以前的版本都运行良好。