Skip to content

DnsResolver cannot discover system DNS servers on Android #132212

Description

@rzikm

Description

DnsResolver (and Dns.Resolve*) is now implemented on all Unix-like platforms by the managed stub resolver in DnsResolverPal.Managed.cs, which is compiled for the -unix TFM and therefore also ships on Android.

When DnsResolverOptions.Servers is empty, the managed resolver obtains the system DNS servers from /etc/resolv.conf via ResolvConf.GetNameServers(). Android has no readable resolver configuration, so this returns an empty list and GetServers() falls back to 127.0.0.1:53:

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.NameResolution/src/System/Net/DnsResolverPal.Managed.cs#L851-L857

The result is that every query issued by a default-constructed DnsResolver times out on Android.

This is the same underlying gap that makes IPInterfaceProperties.DnsAddresses throw PlatformNotSupportedException on Android (see AndroidIPInterfaceProperties and the corresponding assertion in IPInterfacePropertiesTest_Android.cs).

Note that this only affects the system-configured server path. Callers that supply DnsResolverOptions.Servers explicitly work fine on Android.

Suggested fix

Add an Android-specific source for the system DNS servers, e.g.:

  • ConnectivityManager.getLinkProperties(activeNetwork).getDnsServers() through the Android interop layer, or
  • the net.dns1 / net.dns2 system properties via __system_property_get (legacy, unavailable to non-privileged apps on newer API levels), or
  • android_res_nsend / the NDK resolver API.

Test impact

The network tests in DnsResolverTest are currently gated with PlatformDetection.IsNotAndroid for this reason. DnsResolverLoopbackTest is unaffected because it passes explicit servers, and does run on Android.

Note

This issue was drafted by GitHub Copilot.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions