【发布时间】:2017-02-04 21:15:12
【问题描述】:
我在从运行在 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,所以应该没有问题。我还有什么遗漏的吗?
【问题讨论】:
-
为什么需要mongodb驱动的互操作依赖?
-
MongoDB.Driver.Core 依赖于互操作。为什么?我真的不知道。这是驱动程序开发人员的问题。
-
我还尝试添加一个全新的函数,直接引用所需的程序集,结果是一样的。
标签: c# mongodb azure azure-functions