Share via

.NET MAUI Android – HttpRequestException (UnknownHostException) – Unable to resolve host intermittently in production

nandu kathmandi 31 Reputation points
2026-02-23T08:32:25.06+00:00

Hello, I am using .NET MAUI (Android) with HttpClient
This issue occurs in different scenarios. For example, one scenario is:

StartPage → SplashActivity → MainActivity → Home → Atlas → Notification → Home (Card_Click) → after a few minutes, a connection failure occurs in the method LogToAzureStorage.

Second scenario:

StartPage->SplashActivity->MainActivity->a connection failure occurs in the method LogToAzureStorage

In production, I am seeing intermittent non-fatal exceptions in Firebase Crashlytics:

System.Net.Http.HttpRequestException: Connection failure ---> Java.Net.UnknownHostException:Unable to resolve host "fd-comnayname-prod.azurefd.net":No address associated with hostname

Full inner exception:

android.system.GaiException:
android_getaddrinfo failed: EAI_NODATA

This happens while calling APIs like:

GetNotifications()

GetBroadcastMessages()

LogToAzureStorage()

GetJacobsGlobalPrograms()

All APIs use the same base URL:

fd-comnayname-prod.azurefd.net

Stack trace shows it failing inside:

Xamarin.Android.Net.AndroidMessageHandler.DoSendAsync()

Observations:

Not reproducible consistently

Appears for some users in production

Multiple API calls fail at the same time

  • After this failure, a NullReferenceException happens because API result is null
  • We have not identified any network connectivity or DNS-related issues on our side.

Questions:

Can this happen when battery optimisation when app is in background state?

Is there any known issue with AndroidMessageHandler?

Should we implement retry logic for UnknownHostException?

What is the recommended way to handle this scenario in production?

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 880 Reputation points Microsoft External Staff Moderator
    2026-02-23T10:44:25.5633333+00:00

    Hi @nandu kathmandi

    Thanks for reaching out.

    From the log you shared, it means the device could not resolve the hostname to an IP address at that moment. It can appear “random” because mobile connectivity and DNS availability can be intermittent. Put simply, the device could not translate your host name into an IP address at that moment (DNS lookup returned no usable results). That's why when DNS resolution fails, all APIs using the same host will fail at the same time.

    1. Can this happen due to temporary network loss or DNS outage?

    Yes, and it can happen even if your backend server is working fine.

    Some common reasons:

    • The device temporarily loses internet.

    Also, it’s useful to detect and log network state on the device. Remember to configure this tag in your manifest so you can query connectivity state:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    • The phone switches between Wi-Fi and mobile data, or the Wi‑Fi is connected but has no real internet yet. So we can check if the phone can resolve the host to IP when we start application. If it cannot resolve, tell the user to check the WiFi and then exit.
    • DNS problems on the user’s network.

    Your observation that many API calls fail at the same time strongly suggests that the network or DNS was not working at that moment.

    2. Is there any known issue with AndroidMessageHandler DNS resolution?

    In most cases, this is not a "your code is wrong" issue. When it throws UnknownHostException, it’s usually because: android itself couldn’t resolve the name or the network is in transition and resolution temporarily fails.

    3. Should we implement retry logic for UnknownHostException?

    Yes, but with limits.

    UnknownHostException is often transient on mobile, and retries frequently succeed once the device finishes reconnecting or DNS becomes available again. You can try this:

    • Retry 2–3 times only
    • Use exponential backoff (for example: wait 500ms, then 1s, then 2s)
    • Add a small random delay
    • Do not retry forever
    • Use proper HttpClient timeout and cancellation tokens

    If it still fails, show a simple message to the user and allow them to try again.

    Also, keep your current fix: never assume the API result is not null. Even with retries, failure can still happen. Always check for null to avoid NullReferenceException.

    4. Would switching to SocketsHttpHandler help on Android?

    It can help in some cases, and it’s a reasonable thing to test, but I’d treat it as an experiment rather than the main fix. Even with a different handler, if the device can’t resolve DNS at that moment, you can still see the same class of failure. The more important production-grade fixes are: resilience + graceful failure handling + better diagnostics.

    5. What is the recommended way to handle this scenario in production?

    • If a request fails, you must not continue as if you got data. Don’t parse an empty response, don’t return null and then dereference it. Return a failure result and let the UI/service layer handle “no data right now”.
    • Retry a small number of times with exponential backoff.
    • Set timeouts so you fail fast and move into the retry/fallback path instead of hanging. Logging calls (like LogToAzureStorage) should be cancellable and should never block user navigation.
    • After retries, show a straightforward message (“Can’t reach the server right now. Please check your connection and try again.”) and provide a Retry action. For background/telemetry calls, just queue and try later—don’t surface it as an error.

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well. Thanks for your time.

    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.