Dns.GetHostEntryAsync() now returns “hostname nor servname provided, or not known”

Another regression in .NET MAUI

When all these issues with migrating to .NET MAUI (in the previous post) was fixed and the app was sent out to customers, some of the customers could no longer connect to their local server. The logs showed error “hostname nor servname provided, or not known” and no more useful information at all. But luckily, it is a quite specific error that would be easy to find the issue for. But unluckily, the only pages that the search engines found was not related to Android/MAUI and/or was some kind of configuration error.

The method Dns.GetHostEntryAsync() returns an IP-address from a string with a host name or a IP-address. The network code in my app was not changed at all between Xamarin.Forms and MAUI.

Unfortunately, the error did not occur when testing locally, even trying to connect to several different servers. But after testing several different routers, I finally got the error myself. The issue seemed to be a combination of Android manufacturer and router manufacturer. Samsung worked better than Zebra, some router gave the error on both device manufacturers and some routers only on Zebra. Sometimes, switching between different routers would solve the issue, but it would always come back sooner or later.

The .NET runtime was changed from mono to .NET 8 in MAUI and the working code in mono was calling an Android API to get the IP-address, when the new .NET 8 code is calling NameResolutionPal.TryGetAddrInfo() to get the IP-address. (I’m not sure that I found the correct code in .NET runtime.)

Here is the GitHub issue reported to the runtime team:
https://github.com/dotnet/runtime/issues/106969
It is currently tagged with future, which means that it will maybe be fixed in the future. From my previous experience with reporting issues in .NET, it will soon be closed with “closed because of inactivity”, because no one fixed the issue and users gets tired of waiting and starts using workarounds.

Comments

comments