gpt4 book ai didi

c# - 运行 dotnet 隔离的 AzureFunction 不起作用

转载 作者:行者123 更新时间:2023-12-02 05:59:41 24 4
gpt4 key购买 nike

我使用 .net 6.0 开发了 Azure Function v4。它只包含http触发的函数。

本地一切正常,但将其部署到 Azure 后,我通过调用任何端点只能获得 500 状态代码,并且它总是在 Microsoft.Azure.WebJobs.Script.Workers 抛出 InvalidOperationException。 Rpc.RpcFunctionInitationDispatcherLoadBalancer.GetLanguageWorkerChannel :未找到任何初始化的语言 worker

  • 应用程序设置

enter image description here

  • 操作系统:Windows
  • 运行时版本:4.0.1.16815
  • 地点:西欧

更新添加更多信息

项目文件:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.20.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

本地.settings.json


{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"StorageConnectionString": "UseDevelopmentStorage",
"APPINSIGHTS_INSTRUMENTATIONKEY": "MyInstrumentationKey"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
}
}

最佳答案

解决此问题的解决方法之一:

  1. 在 Visual Studio 中创建 Azure Functions(堆栈:.Net 6isolated)并在本地运行:

enter image description here

  • 在 Azure 门户中部署 Function App 后(堆栈:.Net 6,位置:西欧,操作系统:Windows,计划:消耗,函数运行时:隔离)
  • 这是配置: enter image description here

    部署后,函数URL运行成功:

    enter image description here

    <小时/>
  • 正如我所见,名为 WEBSITE_NODE_DEFAULT_VERSION 的设置已添加到您的 .Net Function App 配置设置中。
  • enter image description here

    如果您的函数不是使用 node.js 创建的,并且您没有在代码中显式使用此应用程序设置,那么您可以从函数应用程序中删除此属性。这在MSFT Q&A中有说明。 .

  • 造成此类错误的其他原因是
    • 函数运行时已初始化,但未能初始化语言工作线程。因此,Functions Runtime 检测到工作 channel 尚未启动,并在进一步调用时记录错误消息。
  • 注意:5. 尝试在 Azure 门户中重新创建函数应用程序(.Net 6 - Windows 操作系统 - 西欧位置),并从 Visual Studio 部署 HTTP 触发器函数。或者6. 尝试删除 WEBSITE_NODE_DEFAULT_VERSION 设置 > 保存 > 在 azure 门户中重新启动应用并运行该函数。7. 确保函数应用 local.settings.json 文件中的此设置为 "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"。8、该错误可能是由于Functions Worker版本与SDK版本不匹配导致。如果有任何可用更新,请通过 NuGet Packet Manager 进行更新: enter image description here

    此外,此错误存在于以前版本的 dotnetisolated 5 和 Azure Functions 版本 V3 中。

    引用文献:

    1. azure-functions-dotnet-worker/issues
    2. https://github.com/Azure/azure-functions-host/issues/7618 .
    3. SO Thread1

    关于c# - 运行 dotnet 隔离的 AzureFunction 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70762049/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com