从 azure 函数连接到 MongoDB
Connecting to MongoDB from azure function
我在 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 版本,它就像一块经过微调的手表,所以这似乎是 Mongo 的问题包本身。
我用不同版本的包测试过,这个问题是在2.4.0版本中引入的。所有以前的版本都运行良好。
我在 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 版本,它就像一块经过微调的手表,所以这似乎是 Mongo 的问题包本身。
我用不同版本的包测试过,这个问题是在2.4.0版本中引入的。所有以前的版本都运行良好。