错误CS0006:找不到元数据文件'MongoDB' [英] Error CS0006: Metadata file 'MongoDB' could not be found

查看:120
本文介绍了错误CS0006:找不到元数据文件'MongoDB'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Azure Function,它在`run.csx'中具有以下代码

I have created a Azure Function and it has below code in `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函数时出现错误

I am getting below error while running the azure function

2019-01-11T10:01:14.846 [错误] run.csx(5,27):错误CS0234:类型或名称空间名称'Description'在名称空间'System.ServiceModel'中不存在(丢失了吗?组装参考?)

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):错误CS0246:找不到类型或名称空间名称'MongoDB'(您是否缺少using指令或程序集引用?)

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?)

我什至尝试添加如下所示的名称空间,但是没有运气

I even tried adding namespace like below but no luck

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

推荐答案

这可能是由于功能运行时的差异引起的.

It's probably caused by the difference of Function runtime.

project.json用于〜1运行时的函数,其中代码以.NET Framework为目标,而您创建的函数在〜2运行时在.NET Core env上运行.当我们创建一个新的Function应用程序时,默认情况下,其运行时默认设置为〜2.

project.json is used for functions on ~1 runtime where code targets at .NET Framework, while the function you create is on ~2 runtime which runs on .NET Core env. When we create a new Function app its runtime is set to ~2 by default now.

因此解决方案很简单,删除Function应用程序中的现有功能,并将Function运行时版本更改为〜1(在门户网站中找到,平台功能> Function app设置).然后,您可以按照上述步骤重新创建IoT中心(事件中心)触发器,这次应该可以进行操作了.

So the solution is simple, delete existing functions in the Function app and change Function runtime version to ~1(Find it in portal, Platform features>Function app settings). Then you could recreate an IoT Hub (Event Hub) trigger with steps above, things should work this time.

要使用Function 2.0,请使用function.proj安装软件包.

To work with Function 2.0, use function.proj to install packages.

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="<packageName>" Version="<version>"/>
    </ItemGroup>
</Project>

这篇关于错误CS0006:找不到元数据文件'MongoDB'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆