我在从 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.Core
和 MongoDB.Bson
恢复到版本 2.3.0,它工作得很好tuned watch,看来是Mongo包本身的问题。
我已经使用不同版本的软件包进行了测试,该问题是在 2.4.0 版本中引入的。所有以前的版本都运行良好。
关于c# - 从azure函数连接到MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42045678/