ConfigurationBuilder 在天蓝色功能中不起作用

ConfigurationBuilder not working in azure function(ConfigurationBuilder 在天蓝色功能中不起作用)
本文介绍了ConfigurationBuilder 在天蓝色功能中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS2017 中使用 azure functions 模板项目并选择版本 2 (beta).我将它原封不动地发布并且它有效.

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 Functions (v2.0) 中的配置信息

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

在计算模拟器中执行抛出System.Private.CoreLib:执行函数时出现异常:Function1.Aweton.Labs.AzureFunc1:无法加载文件或程序集Microsoft.Extensions.Configuration,Version=2.1.0.0,Culture=neutral,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
    • Microsoft.Extensions.Configuration.FileExtensions
    • Microsoft.Extensions.Configuration.Json
    • Extensions.Configuration.EnvironmentVariables
    • 可能还有 Microsoft.Extensions.Configuration.UserSecrets

    请参阅下面的更多信息https://www.koskila.net/如何访问-azure-function-apps-settings-from-c/

    这篇关于ConfigurationBuilder 在天蓝色功能中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)