ConfigurationBuilder无法在Azure函数中工作 [英] ConfigurationBuilder not working in azure function

查看:65
本文介绍了ConfigurationBuilder无法在Azure函数中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS2017中使用azure函数模板项目,并选择版本 2(测试版).我没有做任何修改就发布了它.

I'm using azure functions template project in VS2017 and choosing version 2 (beta). I published it unchanged and it worked.

我添加了nuget包 Microsoft.Extensions.Configuration ,并编写了一条语句来初始化 ConfigurationBuilder

I added nuget package Microsoft.Extensions.Configuration and wrote a single statement to initialize an instance of ConfigurationBuilder

public static class Function1
{
    [FunctionName("Function1")]
    public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
    {
        var cb = new ConfigurationBuilder();// <<<<< added line
        log.Info("C# HTTP trigger function processed a request.");

        string name = req.Query["name"];

        string requestBody = new StreamReader(req.Body).ReadToEnd();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        name = name ?? data?.name;

        return name != null
            ? (ActionResult)new OkObjectResult($"Hello, {name}")
            : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
    }
}

使用此代码,函数崩溃并显示500-内部服务器错误,我找不到任何原因.

With this code the function crashes with 500 - internal server error and I cannot find any reason.

我错过了什么吗?如何访问Azure函数(v2.0)中的配置信息

Am I missing something? How do I access configuration information in Azure functions (v2.0)

在Compute Emulator中执行 System.Private.CoreLib:执行函数Function1时发生异常. Aweton.Labs.AzureFunc1:无法加载文件或程序集"Microsoft.Extensions.Configuration,版本= 2.1.0.0,区域性=中性,PublicKeyToken = adb9793829ddae60".该系统找不到指定的文件. System.Private.CoreLib:无法加载指定的文件.

Executing in Compute emulator throws System.Private.CoreLib: Exception while executing function: Function1. Aweton.Labs.AzureFunc1: Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

推荐答案

我遇到了同样的问题.您需要安装以下nuget软件包,这些软件包才能正常运行 您需要安装 Microsoft.Extensions.Configuration 才能首先启动

I was having the same issue. You need following nuget packages to be installed for these to work elegantly You need to install Microsoft.Extensions.Configuration for this to init at first place

另外

  • SetBasePath()需要:
    • Microsoft.Extensions.Configuration.Abstractions
  • SetBasePath() requires:
    • Microsoft.Extensions.Configuration.Abstractions
  • Microsoft.Extensions.Configuration.FileExtensions
  • Microsoft.Extensions.Configuration.Json
  • Microsoft.Extensions.Configuration.FileExtensions
  • Microsoft.Extensions.Configuration.Json
  • Extensions.Configuration.EnvironmentVariables
  • ,可能还有 Microsoft.Extensions.Configuration.UserSecrets
  • Extensions.Configuration.EnvironmentVariables
  • and possibly Microsoft.Extensions.Configuration.UserSecrets

请参阅下面的详细信息 https://www.koskila.net/如何从c/

Please refer below for more info https://www.koskila.net/how-to-access-azure-function-apps-settings-from-c/

这篇关于ConfigurationBuilder无法在Azure函数中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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