Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误CS0006:元数据文件';MongoDB';找不到_C#_Azure_Azure Functions_Azure Cosmosdb_Azure Cosmosdb Mongoapi - Fatal编程技术网

C# 错误CS0006:元数据文件';MongoDB';找不到

C# 错误CS0006:元数据文件';MongoDB';找不到,c#,azure,azure-functions,azure-cosmosdb,azure-cosmosdb-mongoapi,C#,Azure,Azure Functions,Azure Cosmosdb,Azure Cosmosdb Mongoapi,我已经创建了一个Azure函数,它在“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 Sy

我已经创建了一个
Azure函数
,它在“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[错误]run.csx(5,27):错误CS0234:命名空间“System.ServiceModel”中不存在类型或命名空间名称“Description”(是否缺少程序集引用?)

2019-01-11T10:01:15.108[错误]run.csx(6,7):错误CS0246:找不到类型或命名空间名称“MongoDB”(是否缺少using指令或程序集引用?)

我甚至尝试添加如下名称空间,但没有成功

#r "Newtonsoft.Json"
#r "System.Xml"
#r "System.Xml.Linq" 
#r "MongoDB"

这可能是由于函数运行时的差异造成的

project.json
用于~1运行时上的函数,其中代码的目标位于.NET Framework,而您创建的函数位于~2运行时上,该运行时在.NET Core env上运行。当我们创建一个新的函数应用程序时,它的运行时间现在默认设置为~2

因此,解决方案很简单,删除函数应用程序中的现有函数,并将函数运行时版本更改为~1(在门户、平台功能>函数应用程序设置中找到它)。然后,您可以使用上面的步骤重新创建一个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>

netstandard2.0

因为~2运行时是最新的,所以我觉得最好使用它。但是在哪里可以找到使用~2 runtime实现相同功能的文档?@kudlatiger请参阅我的更新,以便在~2 runtime中安装软件包。