简体   繁体   English

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

[英]Error CS0006: Metadata file 'MongoDB' could not be found

I have created a Azure Function and it has below code in `run.csx' 我创建了一个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}");
 }

I am having Project.json as follow 我有如下的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"
    }
  }
 }
}

I am getting below error while running the azure function 我在运行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:14.846 [错误] run.csx(5,27):错误CS0234:名称空间'System.ServiceModel'中不存在类型或名称空间名称'Description'(您是否缺少程序集引用?)

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

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 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. project.json用于〜1运行时中的函数,其中代码以.NET Framework为目标,而您创建的函数位于〜2运行时中,其在.NET Core env上运行。 When we create a new Function app its runtime is set to ~2 by default now. 现在,当我们创建一个新的Function应用时,其运行时默认设置为〜2。

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). 因此,解决方案很简单,删除Function应用程序中的现有功能,并将Function运行时版本更改为〜1(在门户网站中找到,平台功能> Function app设置)。 Then you could recreate an IoT Hub (Event Hub) trigger with steps above, things should work this time. 然后,您可以按照上述步骤重新创建IoT中心(事件中心)触发器,此时一切正常。

To work with Function 2.0, use function.proj to install packages. 要使用Function 2.0,请使用function.proj安装软件包。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CSC错误CS0006:找不到元数据文件&#39;... dll&#39; - 但文件存在 - CSC error CS0006: Metadata file '…dll' could not be found - But file exists vs 2015 Error CS0006 Metadata file.dll'找不到 - vs 2015 Error CS0006 Metadata file .dll' could not be found 错误 CS0006 元数据文件; 找不到fileuploadcontrol.dll&#39; - error CS0006 metadata file; fileuploadcontrol.dll'could not be found 错误CS0006:找不到元数据文件&#39;C:\\ Users \\ ppData \\ Local \\ Temp \\ .sonarqube \\ .static \\ csharp_1.11.0 \\ SonarAnalyzer.zip \\ SonarAnalyzer.dll - error CS0006: Metadata file 'C:\Users\ppData\Local\Temp\.sonarqube\.static\csharp_1.11.0\SonarAnalyzer.zip\SonarAnalyzer.dll' could not be found 如何解决解决方案中现有项目的 c# CS0006 错误 - How solve c# CS0006 error from a existing project in solution Compiling.Net Framework Project 在命令提示符下给出 CS0006 而 Visual Studio 中没有错误,为什么? - Compiling .Net Framework Project at command prompt give CS0006 while there is not error in Visual Studio, why? mono mcs&#39;Winforms Hello World&#39;给出编译错误CS006:找不到元数据文件&#39;cscompmgd.dll&#39; - mono mcs 'Winforms Hello World' gives compile error CS006: Metadata file 'cscompmgd.dll' could not be found 找不到元数据文件“.dll” - Metadata file '.dll' could not be found 找不到元数据文件.dll - Metadata file .dll could not be found 找不到元数据文件的Facades CSC错误 - Metadata file facades dll could not be found CSC error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM