【Azure Developer】.NET Aspire 项目本地调试遇 Grpc.Core.RpcException 异常( Error starting gRPC call ... )

简介: Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot

问题描述

本地调试 .NET Aspire 项目,启动时候遇见 Grpc.Core.RpcException  异常。

错误消息

Aspire.Hosting.Dashboard.Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
     Unhandled exception in circuit 'eREZIUtKB-Z6wCfAhYKkIpVdw_-O9qgpsgft9Yi_DHY'.
     Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.")
      ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
      ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot

 

问题解答

在启动窗口中,可以看见 warn 提示信息: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[8], The ASP.NET Core developer certificate is not trusted. For information about trusting the ASP.NET Core developer certificate, see https://aka.ms/aspnet/https-trust-dev-cert .

根据文档提示,找到了 " 信任 ASP.NET Core HTTPS 开发证书 " 部分的介绍 , 其中提到 dotnet dev-certs https --trust 命令来信任ASP.NET Core HTTPS 开发证书。

其实,通过Visual Studio的异常提示,也能发现需要执行[ dotnet dev-certs https ] 来生成 .NET 开发证书,然后使用 [ dotnet dev-certs https --trust ] 命令信任该证书。

## 生成 .NET的开发证书 
dotnet dev-certs https 

## 信任证书 
dotnet dev-certs https --trust

如下图:

 

完整的错误消息


warn: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[8]

The ASP.NET Core developer certificate is not trusted. For information about trusting the ASP.NET Core developer certificate, see https://aka.ms/aspnet/https-trust-dev-cert.

info: Aspire.Hosting.DistributedApplication[0]

Aspire version: 9.0.0+01ed51919f8df692ececce51048a140615dc759d

info: Aspire.Hosting.DistributedApplication[0]

Distributed application starting.

info: Aspire.Hosting.DistributedApplication[0]

Application host directory is: C:\Users\bulu\source\repos\myAspireApp\myAspireApp.AppHost

info: Aspire.Hosting.DistributedApplication[0]

Now listening on: https://localhost:17068

info: Aspire.Hosting.DistributedApplication[0]

Login to the dashboard at https://localhost:17068/login?t=cb960c5eba7ef8c01e2c2f1ce0d39b3b

info: Aspire.Hosting.DistributedApplication[0]

Distributed application started. Press Ctrl+C to shut down.

fail: Aspire.Hosting.Dashboard.Model.DashboardClient[0]

Error loading data from the resource service.

System.Threading.Tasks.TaskCanceledException: A task was canceled.

at Grpc.Net.Client.Internal.Retry.RetryCallBaseClientStreamReader`2.MoveNext(CancellationToken cancellationToken)

at Grpc.Core.AsyncStreamReaderExtensions.ReadAllAsyncCore[T](IAsyncStreamReader`1 streamReader, CancellationToken cancellationToken)+MoveNext()

at Grpc.Core.AsyncStreamReaderExtensions.ReadAllAsyncCore[T](IAsyncStreamReader`1 streamReader, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()

at Aspire.Dashboard.Model.DashboardClient.<>c__DisplayClass29_1.<<EnsureInitialized>g__WatchResourcesAsync|5>d.MoveNext() in /_/src/Aspire.Dashboard/ResourceService/DashboardClient.cs:line 323

--- End of stack trace from previous location ---

at Aspire.Dashboard.Model.DashboardClient.<>c__DisplayClass29_1.<<EnsureInitialized>g__WatchResourcesAsync|5>d.MoveNext() in /_/src/Aspire.Dashboard/ResourceService/DashboardClient.cs:line 323

--- End of stack trace from previous location ---

at Aspire.Dashboard.Model.DashboardClient.<>c__DisplayClass29_0.<<EnsureInitialized>g__WatchResourcesWithRecoveryAsync|3>d.MoveNext() in /_/src/Aspire.Dashboard/ResourceService/DashboardClient.cs:line 298

--- End of stack trace from previous location ---

at Aspire.Dashboard.Model.DashboardClient.<EnsureInitialized>g__ConnectAndWatchResourcesAsync|29_1(CancellationToken cancellationToken) in /_/src/Aspire.Dashboard/ResourceService/DashboardClient.cs:line 246

fail: Aspire.Hosting.Dashboard.Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]

Unhandled exception in circuit 'YBJjKTNbyeRc-Kms86UR3uEV_Nr2IkH8k4gT6ufwSyI'.

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.")

---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot

at System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)

at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)

at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)

--- End of inner exception stack trace ---

at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.AddHttp2ConnectionAsync(QueueItem queueItem)

at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)

at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)

--- End of inner exception stack trace ---

at Grpc.Net.Client.Internal.Retry.RetryCall`2.StartRetry(Action`1 startCallFunc)

at Grpc.Net.Client.Internal.Retry.RetryCallBase`2.GetResponseCoreAsync()

at Aspire.Dashboard.Model.DashboardClient.<>c__DisplayClass29_0.<<EnsureInitialized>g__ConnectAsync|2>d.MoveNext() in /_/src/Aspire.Dashboard/ResourceService/DashboardClient.cs:line 262

--- End of stack trace from previous location ---

at Aspire.Dashboard.Components.ApplicationName.OnInitializedAsync() in /_/src/Aspire.Dashboard/Components/Controls/ApplicationName.razor.cs:line 32

at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

fail: Aspire.Hosting.Dashboard.Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]

Unhandled exception in circuit 'YBJjKTNbyeRc-Kms86UR3uEV_Nr2IkH8k4gT6ufwSyI'.

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.")

---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot

at System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)

at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)

at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)

--- End of inner exception stack trace ---

at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.AddHttp2ConnectionAsync(QueueItem queueItem)

at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)

at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)

--- End of inner exception stack trace ---

at Grpc.Net.Client.Internal.Retry.RetryCall`2.StartRetry(Action`1 startCallFunc)

at Grpc.Net.Client.Internal.Retry.RetryCallBase`2.GetResponseCoreAsync()

at Aspire.Dashboard.Model.DashboardClient.<>c__DisplayClass29_0.<<EnsureInitialized>g__ConnectAsync|2>d.MoveNext() in /_/src/Aspire.Dashboard/ResourceService/DashboardClient.cs:line 262

--- End of stack trace from previous location ---

at Aspire.Dashboard.Components.ApplicationName.OnInitializedAsync() in /_/src/Aspire.Dashboard/Components/Controls/ApplicationName.razor.cs:line 32

at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

 

参考资料


信任 ASP.NET Core HTTPS 开发证书 : https://learn.microsoft.com/zh-cn/aspnet/core/security/enforcing-ssl?view=aspnetcore-9.0&tabs=visual-studio%2Clinux-sles#trust-the-aspnet-core-https-development-certificate

 

 

 


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
1月前
|
开发框架 前端开发 .NET
一个适用于 .NET 的开源整洁架构项目模板
一个适用于 .NET 的开源整洁架构项目模板
57 26
|
3月前
|
开发框架 .NET C#
在 ASP.NET Core 中创建 gRPC 客户端和服务器
本文介绍了如何使用 gRPC 框架搭建一个简单的“Hello World”示例。首先创建了一个名为 GrpcDemo 的解决方案,其中包含一个 gRPC 服务端项目 GrpcServer 和一个客户端项目 GrpcClient。服务端通过定义 `greeter.proto` 文件中的服务和消息类型,实现了一个简单的问候服务 `GreeterService`。客户端则通过 gRPC 客户端库连接到服务端并调用其 `SayHello` 方法,展示了 gRPC 在 C# 中的基本使用方法。
64 5
在 ASP.NET Core 中创建 gRPC 客户端和服务器
|
3月前
|
开发框架 网络协议 .NET
C#/.NET/.NET Core优秀项目和框架2024年10月简报
C#/.NET/.NET Core优秀项目和框架2024年10月简报
113 3
|
4月前
|
安全 网络安全 数据安全/隐私保护
【Azure Developer】System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
|
4月前
|
开发框架 前端开发 API
C#/.NET/.NET Core优秀项目和框架2024年9月简报
C#/.NET/.NET Core优秀项目和框架2024年9月简报
|
2月前
|
监控 前端开发 API
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
|
5月前
|
存储 开发框架 前端开发
ASP.NET MVC 迅速集成 SignalR
ASP.NET MVC 迅速集成 SignalR
114 0
|
5月前
|
开发框架 前端开发 JavaScript
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
72 7
|
6月前
|
开发框架 前端开发 .NET
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
85 0
|
6月前
|
开发框架 前端开发 安全
ASP.NET MVC 如何使用 Form Authentication?
ASP.NET MVC 如何使用 Form Authentication?
101 0

热门文章

最新文章