A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
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 serverlines 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:
Check how many certificates are listed underopenssl s_client -connect <your-host>:443 -servername <your-host> -showcertsCertificate chainand 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 runadb logcat -d > logcat.txt. Please look for theNetworkSecurityConfigline.Using Network Security Config from resource network_security_config debugBuild: trueconfirms your config is applied, whileNo Network Security Config specified, using platform defaultmeans it isn't. The fullSSLHandshakeException/CertPathValidatorExceptionstack 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.releaseandadb 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>. Trustingusercertificates only helps if that CA is actually installed on the emulator, anddebug-overridesonly 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, placenetwork_security_config.xmlinPlatforms/Android/Resources/xmlwith the AndroidResource build action, and reference it from the<application>element inPlatforms/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
opensslchain output for the exact host name the app calls. - The
NetworkSecurityConfigline from logcat, yournetwork_security_config.xml, and the<application>element fromAndroidManifest.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.