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

2

本文介绍了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 在天蓝色功能中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

    The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14