.NET MAUI Android HttpClient – SSL Certificate Validation Error (Trust Anchor for Certification Path Not Found)

Vignesh Palthurai 70 Reputation points
2026-12-03T15:03:21.56+00:00

Hi ,

I'm facing an SSL certificate validation issue while calling our API from a .NET MAUI Android application.

Our API is hosted behind Azure Application Gateway, and we are using the Application Gateway URL provided by our backend team.

The same API is working as expected in Postman, and I'm able to retrieve the response successfully.

I also tested the endpoint directly using the Chrome browser in BrowserStack App Live, and it returns the response successfully. However, when I call the same endpoint from our MAUI Android application, I'm unable to retrieve the response.

While debugging the application, I found the following exception:

Java.Security.Cert.CertPathValidatorException: Trust anchor for certification path not found

Things we have verified so far:

  1. The API is working in Postman, with SSL certificate verification enabled.

The endpoint returns a response when accessed directly through the BrowserStack Chrome browser.

Our backend team confirmed that a valid SSL certificate is configured on the Application Gateway.

The certificate chain was checked, and the team confirmed that the Android and Apple certificate checker results are the same.

We are using the standard HttpClient in our MAUI application without any custom certificate validation handler.

I also tried configuring Android Network Security Config to trust system and user certificates in Debug mode, but the issue still persists.

Development Environment:

.NET MAUI 10

Android application

Testing using a local Android emulator and BrowserStack App Live

Standard HttpClient

Could you please help us identify why the Android application is failing to validate the SSL certificate even though the same API works in Postman and the browser?

Is there any additional configuration required in .NET MAUI Android or Android HttpClient to resolve this issue?

Thanks.

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

2 answers

Sort by: Newest
  1. Harry Nguyen (WICLOUD CORPORATION) 1,025 Reputation points Microsoft External Staff Moderator
    2026-12-04T03:57:20.84+00:00

    Hi @Vignesh Palthurai ,

    Thanks for reaching out and for sharing the detailed troubleshooting results. Since the API works in Postman and Chrome, and your backend team has already checked the certificate configuration, I'd suggest narrowing the investigation to what the Android app actually receives and trusts during the TLS handshake.

    Why Chrome can succeed while the app fails

    Trust anchor for certification path not found means Android couldn't build a chain from the server certificate to a CA it trusts. Chrome on Android uses its own certificate verifier and root store, and browsers can often work around a missing intermediate certificate. Your app, on the other hand, relies on Android's platform validation: the chain sent by the server, the device's trust store, and your app's Network Security Config.

    Android documents three common causes for this exact exception: an unknown CA, a self-signed certificate, or a server that doesn't send the intermediate CA certificate (Security with network protocols). When a public endpoint works in a browser but not in an Android app, an incomplete chain is one of the most common reasons, so it's worth verifying first.

    1. Compare the handlers (logging only, no bypass)

    On .NET 10 Android, the default HttpClient typically uses the native AndroidMessageHandler, which relies on Android's networking stack (HttpURLConnection). To help determine whether the failure is specific to this handler, and to see which certificates the app actually receives, could you run the helper below? It sends the same request three times: with the default handler unchanged, with AndroidMessageHandler plus logging, and with SocketsHttpHandler plus logging. The callbacks only log and then return the original validation result, so certificate validation is not changed or bypassed.

    using System.Net.Security;
    
    public static class TlsDiagnostics
    {
        public static async Task RunAsync(string apiUrl)
        {
            // 1) Default handler, unchanged (captures the original exception)
            await TryAsync("Default", new HttpClientHandler(), apiUrl);
    
    #if ANDROID
            // 2) AndroidMessageHandler with logging only
            var androidHandler = new Xamarin.Android.Net.AndroidMessageHandler
            {
                ServerCertificateCustomValidationCallback = (request, cert, chain, errors) =>
                {
                    Console.WriteLine($"[TLS][Android] errors={errors} | Leaf: {cert?.Subject} | Issuer: {cert?.Issuer}");
                    if (chain is not null)
                    {
                        // Certificates presented by the server during the handshake
                        foreach (var c in chain.ChainPolicy.ExtraStore)
                            Console.WriteLine($"[TLS][Android] Sent by server: {c.Subject} <- {c.Issuer}");
                    }
                    return errors == SslPolicyErrors.None; // keep the default decision
                }
            };
            await TryAsync("AndroidMessageHandler", androidHandler, apiUrl);
    #endif
    
            // 3) SocketsHttpHandler with logging only
            var socketsHandler = new SocketsHttpHandler();
            socketsHandler.SslOptions.RemoteCertificateValidationCallback = (sender, cert, chain, errors) =>
            {
                Console.WriteLine($"[TLS][Sockets] errors={errors} | Leaf: {cert?.Subject} | Issuer: {cert?.Issuer}");
                if (chain is not null)
                {
                    foreach (var status in chain.ChainStatus)
                        Console.WriteLine($"[TLS][Sockets] ChainStatus: {status.Status} - {status.StatusInformation}");
                }
                return errors == SslPolicyErrors.None; // keep the default decision
            };
            await TryAsync("SocketsHttpHandler", socketsHandler, apiUrl);
        }
    
        private static async Task TryAsync(string name, HttpMessageHandler handler, string apiUrl)
        {
            using var client = new HttpClient(handler);
            try
            {
                using var response = await client.GetAsync(apiUrl);
                // Any HTTP status code (even 401/404) means the TLS handshake succeeded
                Console.WriteLine($"[TLS][{name}] HTTP {(int)response.StatusCode}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[TLS][{name}] FAILED: {ex}"); // full exception, including inner exceptions
            }
        }
    }
    

    Please test this on the same Android emulator, using the same endpoint and build configuration (for example, await TlsDiagnostics.RunAsync(apiUrl); from a test button), and remove it after testing. The output appears in logcat under the DOTNET tag. When a logging callback is set, a rejected certificate shows up as "rejected by the provided RemoteCertificateValidationCallback". That's why the first run without a callback is included: it captures the original exception.

    The results would help narrow down the issue:

    • If both handlers fail, I'd investigate the certificate chain and trust configuration seen by the Android emulator. The Sent by server lines show how many certificates the gateway sends and who issued them.
    • If only the default handler fails, I'd look further into the Android-specific path, such as the Network Security Config applied to this host and the full Java exception.
    • If both handlers succeed, I'd review the original request configuration (base URL/host name, any custom or DI-registered HttpClient/handler, Debug vs Release) and the execution environment.

    2. Additional logs to narrow it down

    • What the gateway actually sends: In addition to the SSL Labs test Bruce mentioned, please check whether Chain issues shows Incomplete, or whether any certificate under Certification Paths is marked Extra download (meaning the server isn't sending it). From the same machine/network as the emulator, you can also run:
        openssl s_client -connect <your-host>:443 -servername <your-host> -showcerts
      
      Check how many certificates are listed under Certificate chain and who issued them. If the issuer isn't the CA your backend team expects (for example, a corporate proxy, antivirus, or debugging proxy CA), TLS is being inspected on that network.
    • Logcat from app start: Run adb logcat -c, start the app and reproduce the call, then run adb logcat -d > logcat.txt. Please look for the NetworkSecurityConfig line. Using Network Security Config from resource network_security_config debugBuild: true confirms your config is applied, while No Network Security Config specified, using platform default means it isn't. The full SSLHandshakeException / CertPathValidatorException stack trace and the [TLS] lines are also useful.
    • Emulator trust store: Please note the Android version and API level (adb shell getprop ro.build.version.release and adb shell getprop ro.build.version.sdk), and check whether your chain's root CA is listed under Trusted credentials > System in the emulator's security settings.
    • Environment comparison: If the app also fails on BrowserStack devices (and BrowserStack Local isn't routing traffic through your network), local TLS inspection is less likely and the chain or trust store becomes the main suspect. If it fails only on your local emulator, or only on certain Android versions, that points to the local network or to a trust store difference.

    3. Common causes and documented fixes

    • Only the leaf certificate is sent (or SSL Labs shows "Extra download"): Application Gateway requires the entire certificate chain (root, intermediates and leaf) to be uploaded with the listener certificate (TLS termination with Application Gateway). Re-uploading the listener PFX (or updating the Key Vault certificate) with the full chain is the fix. Android's guidance for this case is also to include the intermediate CA in the server chain.
    • Self-signed certificate or private/internal CA: For a public endpoint, use a certificate from a publicly trusted CA. If a private CA is intended, trust that CA only for your API domain with <domain-config> + <trust-anchors> in the Network Security Config, instead of disabling validation.
    • Proxy, antivirus or debugging-tool CA in the chain: Exclude the API host from TLS inspection, or trust that CA in Debug builds only with <debug-overrides>. Trusting user certificates only helps if that CA is actually installed on the emulator, and debug-overrides only applies when the app is debuggable. This may explain why your earlier Network Security Config change didn't help.
    • Complete public chain, but failures only on some Android versions: The root CA may be missing from that Android version's system store. Use a chain that's trusted on the Android versions you support, or add the CA as an additional trust anchor in the Network Security Config.
    • Network Security Config not applied, or a <domain-config> restricting the CAs for this host: In .NET MAUI, place network_security_config.xml in Platforms/Android/Resources/xml with the AndroidResource build action, and reference it from the <application> element in Platforms/Android/AndroidManifest.xml (.NET MAUI Android network configuration). If several <domain-config> entries match the host, Android uses the most specific one.

    4. Information that would help

    Could you share:

    • The output of all three runs, including the full exception and inner exception for any run that fails.
    • The SSL Labs chain result or the openssl chain output for the exact host name the app calls.
    • The NetworkSecurityConfig line from logcat, your network_security_config.xml, and the <application> element from AndroidManifest.xml.
    • The Android version/API level, and whether the issue occurs on both the local emulator and BrowserStack.

    For reference, Microsoft documents AndroidMessageHandler and SocketsHttpHandler.

    This should help identify the next troubleshooting step without changing or bypassing certificate validation.

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

    Was this answer helpful?

    0 comments No comments

  2. Bruce (SqlWork.com) 85,506 Reputation points
    2026-12-03T17:46:04.4233333+00:00

    Both IOS and Android are fussier about certificate chains. Also application code can not override certificate validation. you can use ssl labs certificate test to help debug:

    https://www.ssllabs.com/ssltest/

    note: your network team probably installed the Azure Application Gateway ssl certificate. Be sure is not a self signed certificate and a publicly trusted provider.

    if you control the Android devices you can manually install and trust the certificate. google for instructions for your particular device.

    Was this answer helpful?

    0 comments No comments

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.