Using a DelegatingHandler in HttpClient class from windows forms - Inner handler has not been set
I should have realized this sooner but it makes sense to perhaps set the inner handler to the default handler that HttpClient
uses. So inside your child class of DelegatingHandler
you should set your inner handler to the default handler used by HttpClient
like so:
public CkApiMessageHandler(string email, string password, Guid moduleId)
{
_email = email;
_password = password;
_moduleId = moduleId;
InnerHandler = new HttpClientHandler();
}
Adrian answer is correct. You have to set an inner handler for your custom handler, but there is a better way to set the inner handler.
public MyDelegatingHandler( ) : base( new HttpClientHandler( ) )
Or you can use the HttpClientFactory
_client = HttpClientFactory.Create(new CKEnterprise.Common.CkApiMessageHandler(email, password))
https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/httpclient-message-handlers#adding-message-handlers-to-the-client-pipeline