c# - 从azure函数连接到MongoDB

标签 c# mongodb azure azure-functions

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

我已将 mongoDB 依赖项添加到 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,所以应该没有问题。还有什么我遗漏的吗?

最佳答案

我对他们的 JIRA 问题进行了一些挖掘,发现 JIRA ISSUE 。我已将 MongoDB.Driver MongoDB.Driver.CoreMongoDB.Bson 恢复到版本 2.3.0,它工作得很好tuned watch,看来是Mongo包本身的问题。

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

关于c# - 从azure函数连接到MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42045678/

相关文章:

c# - 如何在 C# 中比较字符串和字符串数组?

c# - ASP.NET 5/MVC 6 中基于约定的绑定(bind)

c# - 找不到 System.Windows.Point

javascript - meteor Android 应用程序无法连接到服务器

Azure Web 应用程序 (Windows) - 在调用 Entity Framework Core 的 CILJit::compileMethod 期间停止

C# 将字符串从 foreach 循环传递给方法

c# - 尝试在 MongoDB MapReduce 调用中包含 Query

node.js - meteor 从第二个 mongo 数据库中没有获取数据

azure - Azure DevOps 管道中的访问被拒绝问题

api - Azure API 应用程序中基于角色的访问控制