问题描述
我在 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 在天蓝色功能中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!