-
Notifications
You must be signed in to change notification settings - Fork 7
The system cannot find the file specified in Production #7
Description
Hi @uhaciogullari, we need your help please.
Running in azure web app, we encountered weird issue when trying to create the httpClient, this happens all the time to a specific server only.
Error: The system cannot find the file specified | NetworkInformationException | at System.Net.NetworkInformation.SystemIPGlobalProperties.GetFixedInfo()
↵ at System.Net.NetworkInformation.SystemIPGlobalProperties.get_FixedInfo()
↵ at System.Net.NetworkInformation.SystemIPGlobalProperties.get_DomainName()
↵ at System.Net.CookieContainer..ctor()
↵ at System.Net.Http.HttpClientHandler..ctor()
↵ at HttpClientFactoryLite.DefaultHttpMessageHandlerBuilder..ctor()
↵ at HttpClientFactoryLite.HttpClientFactory.CreateHandlerEntry(String name)
↵ at HttpClientFactoryLite.HttpClientFactory.<>c__DisplayClass10_0.<.ctor>b__1()
↵ at System.Lazy1.CreateValue() ↵--- End of stack trace from previous location where exception was thrown --- ↵ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() ↵ at System.Lazy1.get_Value()
↵ at HttpClientFactoryLite.HttpClientFactory.CreateHandler(String name)
↵ at HttpClientFactoryLite.HttpClientFactory.CreateClient(String name)
This is our code in creating the http client factory:
private const string HTTP_CLIENT_FACTORY_NAME = "test";
private static Lazy<IHttpClientFactory> httpClientFactoryLazy = new Lazy<IHttpClientFactory>(() =>
{
var httpClientFactory = new HttpClientFactory();
//Source: https://github.com/uhaciogullari/HttpClientFactoryLite
httpClientFactory.Register(HTTP_CLIENT_FACTORY_NAME, builder => builder
.AddHttpMessageHandler(() => new PolicyHttpMessageHandler())
// Customize the primary HttpClientHandler
.ConfigurePrimaryHttpMessageHandler(() =>
{
var httpClientHandler = new HttpClientHandler()
{
//Allow Cookies to be set manually in the Headers. Source: https://stackoverflow.com/questions/12373738/how-do-i-set-a-cookie-on-httpclients-httprequestmessage
UseCookies = false
};
return httpClientHandler;
})
.SetHandlerLifetime(TimeSpan.FromMinutes(5)));
return httpClientFactory;
}, LazyThreadSafetyMode.ExecutionAndPublication);
private static IHttpClientFactory httpClientFactory
{
get
{
return httpClientFactoryLazy.Value;
}
}
private static HttpClient getHttpClient()
{
return httpClientFactory.CreateClient(HTTP_CLIENT_FACTORY_NAME);
}