Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

The system cannot find the file specified in Production #7

@penguinawesome

Description

@penguinawesome

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions