Question Details

No question body available.

Tags

.net-core restsharp client-certificates

Answers (2)

Accepted Answer Available
Accepted Answer
July 1, 2026 Score: 3 Rep: 328 Quality: High Completeness: 80%

Maybe you should try this:

var options = new RestClientOptions("https://example.com/endpoint")
{
    ConfigureMessageHandler = _ => new SocketsHttpHandler()
    {
        SslOptions = new SslClientAuthenticationOptions()
        {
            ClientCertificates = cert
        }
        // more config options for SocketsHttpHandler can be added, if any
    }
};

var client = new RestClient(options); // originally "https://example.com/endpoint"

Explanation:

  • RestSharp's RestClient constructor can accept a RestClientOptions object instead of its normal way, which is the endpoint URL. Such RestClientOptions object itself has a ConfigureMessageHandler property which allows you to change the handler, which should be a lambda returning an object of class HttpMessageHandler or a class derives from it. And SocketsHttpHandler happens to derive from it, so we have a way to hook into it.

  • Didn't try that myself to see if it solves your "RespondEnded" error because I really have no way to access your system. If indeed using SocketsHttpHandler can solve it as you already tested it with a simple console program which uses it directly, then it should worth your trying.

July 1, 2026 Score: 1 Rep: 135,414 Quality: Medium Completeness: 80%

Try setting ClientCertificateOptions to Automatic. Otherwise you need to specify all options correctly.

using var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
handler.ClientCertificates.Add(cert);

If that doesn't work, you can pass the SocketsHttpHandler to RestClient's constructor :

using var handler = new SocketsHttpHandler();
handler.SslOptions.ClientCertificates = [cert];

using var client = new RestClient(handler);

All handlers inherit from HttpMessageHandler.


HttpClient in .NET Core always uses SocketsHttpHandler outside the browser. This is explained in the class docs and can be verified in the source code :

#if TARGETWASI
using System.Diagnostics;
using System.Net.Http.Metrics;
using HttpHandlerType = System.Net.Http.WasiHttpHandler;
#elif TARGETBROWSER
using System.Diagnostics;
using System.Net.Http.Metrics;
using HttpHandlerType = System.Net.Http.BrowserHttpHandler;
#else
using HttpHandlerType = System.Net.Http.SocketsHttpHandler;
#endif

I suspect the difference is the default value of ClientCertificateOptions, which is Manual by default, set in the default HttpClientHandler constructor

    public HttpClientHandler()
    {
        _underlyingHandler = new HttpHandlerType();

ClientCertificateOptions = ClientCertificateOption.Manual; }

That property delegates to the actual implementation's ClientCertificateOptions. In SocketsHttpHandler it's internal. This works through the also internal HttpConnectionSettings class.

In the HttpConnectionSettings, the value is set to Automatic