错误 CS0006:找不到元数据文件 'MongoDB'
Error CS0006: Metadata file 'MongoDB' could not be found
我创建了一个 Azure Function
,它在 `run.csx'
中有以下代码
using System;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using MongoDB.Bson.IO;
using MongoDB.Bson;
using MongoDB;
using MongoDB.Driver;
using System.Security.Authentication;
using System.Text;
using Newtonsoft.Json;
public static void Run(string myIoTHubMessage, ILogger log)
{
log.LogInformation($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");
}
我Project.json
如下
{
"frameworks": {
"net46":{
"dependencies": {
"Newtonsoft.Json": "10.0.3",
"System.ServiceModel.Primitives":"4.4.0",
"MongoDB.Bson": "2.4.0",
"MongoDB.Driver": "2.4.0",
"MongoDB.Driver.Core": "2.4.0"
}
}
}
}
我在 运行 azure 函数
时遇到错误
2019-01-11T10:01:14.846 [Error] run.csx(5,27): error CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)
2019-01-11T10:01:15.108 [Error] run.csx(6,7): error CS0246: The type or namespace name 'MongoDB' could not be found (are you missing a using directive or an assembly reference?)
我什至试过像下面这样添加命名空间,但没有成功
#r "Newtonsoft.Json"
#r "System.Xml"
#r "System.Xml.Linq"
#r "MongoDB"
可能是Function运行时不同造成的
project.json
用于 ~1 运行时上的函数,其中代码以 .NET Framework 为目标,而您创建的函数是在 ~2 运行时上运行的,它在 .NET Core 环境中运行。当我们创建一个新的函数应用程序时,它的运行时间现在默认设置为 ~2。
所以解决方法很简单,删除Function app中已有的函数,将Function runtime version改为~1(在portal中找到,Platform features>Function app settings)。然后您可以使用上述步骤重新创建一个 IoT 中心(事件中心)触发器,这次应该可以正常工作了。
要使用 Function 2.0,请使用 function.proj
安装包。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="<packageName>" Version="<version>"/>
</ItemGroup>
</Project>
我创建了一个 Azure Function
,它在 `run.csx'
using System;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using MongoDB.Bson.IO;
using MongoDB.Bson;
using MongoDB;
using MongoDB.Driver;
using System.Security.Authentication;
using System.Text;
using Newtonsoft.Json;
public static void Run(string myIoTHubMessage, ILogger log)
{
log.LogInformation($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");
}
我Project.json
如下
{
"frameworks": {
"net46":{
"dependencies": {
"Newtonsoft.Json": "10.0.3",
"System.ServiceModel.Primitives":"4.4.0",
"MongoDB.Bson": "2.4.0",
"MongoDB.Driver": "2.4.0",
"MongoDB.Driver.Core": "2.4.0"
}
}
}
}
我在 运行 azure 函数
时遇到错误2019-01-11T10:01:14.846 [Error] run.csx(5,27): error CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)
2019-01-11T10:01:15.108 [Error] run.csx(6,7): error CS0246: The type or namespace name 'MongoDB' could not be found (are you missing a using directive or an assembly reference?)
我什至试过像下面这样添加命名空间,但没有成功
#r "Newtonsoft.Json"
#r "System.Xml"
#r "System.Xml.Linq"
#r "MongoDB"
可能是Function运行时不同造成的
project.json
用于 ~1 运行时上的函数,其中代码以 .NET Framework 为目标,而您创建的函数是在 ~2 运行时上运行的,它在 .NET Core 环境中运行。当我们创建一个新的函数应用程序时,它的运行时间现在默认设置为 ~2。
所以解决方法很简单,删除Function app中已有的函数,将Function runtime version改为~1(在portal中找到,Platform features>Function app settings)。然后您可以使用上述步骤重新创建一个 IoT 中心(事件中心)触发器,这次应该可以正常工作了。
要使用 Function 2.0,请使用 function.proj
安装包。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="<packageName>" Version="<version>"/>
</ItemGroup>
</Project>