从a /a>。我正在尝试使用功能运行时的.NET 6和V4在隔离过程中构建Azure函数,以作为Linux容器图像运行。
我遵循 Microsoft Guide 要使用HTTP触发器进行工作,运行示例功能。然后,我开始将代码添加到应用程序并立即被阻止的过程。这是我 program
的 main
方法:
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration((context, builder) =>
{
builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.AddEnvironmentVariables();
})
.ConfigureServices((context, collection) => ConfigureServices(collection, context.Configuration))
.Build();
host.Run();
}
我发现该函数正常工作,直到我添加行 builder.addenvironmentvariables(); 。只有此更改,该功能突然在启动时突然崩溃,例外:
system.invalidoperationException in microsoft.azure.webjobs.script.workers.rpc.rpc.rpcfunctioninvocationdispatcherloadbalancer.getLanguageWormageWorkerWorkerChannel
中隐藏着一条消息,那里隐藏着一条消息,说“我没有找到任何初始化的语言工人”我不会告诉你什么或为什么”。
在我的特殊用例中,我取决于能够将环境变量用作配置源的功能,因为我的管道将将其传递给ARM模板作为站点配置。所以我的问题是,如何在孤立模式下进行?
This follows on from a previous question. I'm trying to build an Azure function to run as a Linux container image in an isolated process using .NET 6 and v4 of the functions runtime.
I have followed the Microsoft guide to get a working, running sample function with HTTP trigger. I have then begun the process of adding my code to the app and immediately become blocked. This is the Main
method of my Program
:
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration((context, builder) =>
{
builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.AddEnvironmentVariables();
})
.ConfigureServices((context, collection) => ConfigureServices(collection, context.Configuration))
.Build();
host.Run();
}
What I've discovered is that the function works fine until I add the line builder.AddEnvironmentVariables();
. With this change only, the function suddenly craps out on startup with the exception:
System.InvalidOperationException at Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcFunctionInvocationDispatcherLoadBalancer.GetLanguageWorkerChannel
There's a message hidden in there saying "Did not find any initialized language workers" which I understand is Azure Function language for "something bad happened during startup but I'm not going to tell you what or why".
In my particular use case I'm depending on the function being able to use environment variables as a config source because my pipeline will be passing these to the ARM template as site config. So my question is, how is this possible in isolated mode?
发布评论
评论(1)
好吧,事实证明,环境变量是通过调用
configurefunctionsworkerDefaults
自动添加的。您可以在。我不知道为什么在传统的dotnet核心方式中添加环境变量作为配置源会导致整个事情爆炸,但至少我没有被封锁。希望这对别人有帮助。还指出,这将影响您使用
configureAppConfiguration
和configurefunctionsworkerDefaults
Extensions的顺序。由于后者将控制台输入和环境变量作为配置源,因此,如果您还使用appSettings.json。 em>configureAppConfiguration
。因此,我的程序
看起来像这样:Well it turns out that environment variables are added automatically by the call to
ConfigureFunctionsWorkerDefaults
. You can see this here in WorkerHostBuilderExtensions. I have no idea why attempting to add environment variables as a config source in the traditional dotnet core way causes the whole thing to blow up, but at least I'm unblocked. Hope this helps someone else.It's woth also pointing out that this will affect the order in which you use the
ConfigureAppConfiguration
andConfigureFunctionsWorkerDefaults
extensions. Since the latter adds console input and environment variables as config sources, if you also use an appsettings.json on disk it's likely you'll want environment variables to override its config soConfigureFunctionsWorkerDefaults
would need to be called afterConfigureAppConfiguration
. Therefore myProgram
looks like this: