"An invalid request URI was provided" error when using Azure search provider


Description

Search queries against Azure Search might fail with similar errors in the logs:
Exception: System.InvalidOperationException
Message: An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
Source: System.Net.Http
   at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
   at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Sitecore.ContentSearch.Azure.Http.HttpClientWrapper.Get(String requestUri, IEnumerable`1 headers)
   at Sitecore.ContentSearch.Azure.Http.SearchServiceClient.Search(String expression
   at Sitecore.ContentSearch.Azure.Http.CompositeSearchService.Search(String expression)
...
Exception: System.InvalidOperationException
Message: This instance has already started one or more requests. Properties can only be modified before sending the first request.
Source: System.Net.Http
...

Solution

To resolve the issue, consider one of the following options: