gpt4 book ai didi

c# - Azure 函数(dotnet-isolated)无法启动,并出现 Grpc.Core.RpcException : StatusCode ="Unavailable" - Mac M1

转载 作者:行者123 更新时间:2023-12-02 06:35:59 25 4
gpt4 key购买 nike

我最近获得了一台 Mac M1,并且正在设置我的计算机以进行 Azure Function(dotnet-isolated)开发。

我按照以下文档进行操作,该文档在我的 Windows 10 计算机上运行得非常好。 https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-csharp?tabs=azure-cli%2Cisolated-process

以下是 Mac 中的设置,

% func --版本4.0.4895

% dotnet --list-sdks6.0.403 [/usr/local/share/dotnet/sdk]

% azure-functions-core-tools@4

% az --版本azure-cli 2.42.0

核心2.42.0遥测1.0.8

依赖关系:MSAL 1.20.0 azure 管理资源21.1.0b1

完成上述安装后,使用以下命令创建一个新函数

% func new --template "Http Trigger"--name MyHttpTrigger

然后当我尝试使用启动该功能时% 函数开始

我收到以下错误......

MyHttpTrigger: [GET,POST] http://localhost:7071/api/MyHttpTrigger
For detailed output, run func with --verbose flag.
[2022-11-30T09:21:10.868Z] Unhandled exception. Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake. IOException: Unable to write data to the transport connection: Broken pipe. SocketException: Broken pipe", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
[2022-11-30T09:21:10.868Z] ---> System.IO.IOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake.
[2022-11-30T09:21:10.868Z] ---> System.IO.IOException: Unable to write data to the transport connection: Broken pipe.
[2022-11-30T09:21:10.868Z] ---> System.Net.Sockets.SocketException (32): Broken pipe
[2022-11-30T09:21:10.868Z] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow)

csproj

    <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="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>

程序.cs

using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();

功能

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace LocalFunctionProj
{
public class MyHttpTrigger
{
private readonly ILogger _logger;

public MyHttpTrigger(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<MyHttpTrigger>();
}

[Function("MyHttpTrigger")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

response.WriteString("Welcome to Azure Functions!");

return response;
}
}
}

本地.settings.json

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}

launchSettings.json

{
"profiles": {
"LocalFunctionProj": {
"commandName": "Project",
"commandLineArgs": "--port 7146",
"launchBrowser": false
}
}
}

请对我在这里缺少的内容有任何意见吗?

最佳答案

我知道这已经晚了,但是,我最近也遇到了这个问题,结果是我的 Program.cs 中的调用顺序问题。简而言之,我在 ConfigureAppConfiguration 之前调用了 ConfigureFunctionsWorkerDefaults。在这件事上,我用头撞墙的时间比我愿意承认的要长得多。一旦我改变了调用顺序,一切都很好。例如:

var host = new HostBuilder()
.ConfigureAppConfiguration(builder => builder.AddEnvironmentVariables())
.ConfigureFunctionsWorkerDefaults()
.Build();

希望这对其他人有帮助。

关于c# - Azure 函数(dotnet-isolated)无法启动,并出现 Grpc.Core.RpcException : StatusCode ="Unavailable" - Mac M1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74625626/

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