I am using Visual Studio 2017 and .NET Core 2.x. I have set up two projects. The first is the backend API (https://localhost:51637). The second is the front end website (https://localhost:54146). The front end website calls the back end API. They are both running locally on my machine.
Problem is, when the front end tries to send a request to the API, I get this exeption
info: Microsoft.AspNetCore.Server.Kestrel[20]
Connection id "0HLKNTHFLCEA9" request processing ended abnormally.
System.IO.IOException: The decryption operation failed, see inner exception. ---> System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
--- End of inner exception stack trace ---
at System.Net.Security.SslStreamInternal.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory`1 buffer)
at Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.AdaptedPipeline.ReadInputAsync(Stream stream)
at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.ReadAsync(CancellationToken token)
at System.IO.Pipelines.Pipe.DefaultPipeReader.ReadAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.BeginRead(ValueTask`1& awaitable)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication`1 application)
This arcane error may also occur between two .NET Core applications under development where .NET app is your self-hosted website or API and the other is a .NET client console app or whatever.
The server-side error is as per OP dump above, and the client-side error is:
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
Run this to trust the development certificate and resolve the problem.
dotnet dev-certs https -t -v
More information here.
https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx
Turns out, the API certificate wasn't trusted by my browser (Firefox). To fix this
The front end website will now be able to call the back end API successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With