-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] NetworkInterface.GetAllNetworkInterfaces failed with NetworkInformationException (message: Success) #75809
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionOn Android 11 release build, I was encountering System.Net.NetworkInformation.NetworkInformationException when called System.Net.NetworkInterface.NetworkInformation.GetAllNetworkInterfaces, and the error string is just success. I have added two permissions: INTERNET and ACCESS_NETWORK_STATE to which no avail. I think it's worth mentioning. I saw a log category named DOTNET_LINK so I reported the issue here. Reproduction StepsUsing System.Net namespace, call NetworkInterface.GetAllNetworkInterfaces Expected behaviorThe function completes with no exception Actual behaviorThe function throws System.Net.NetworkInformationException Regression?No response Known WorkaroundsNo response Configuration.NET 6.0.9 Other informationI skimmed through the PRs and there was a change to exclusively use the Xamarin's implementation of getifaddrs recently. But on Android 11 Google blocked NETLINK_ROUTE family socket from being bind. This is also the log that I was getting from adb I think it's correspond to this. I hope I'm right. One small note, I think this quirk is per vendor distribution, as my Xiaomi phone does not seems have this problem. Related issues about this blocking .
|
Thanks - could you paste in the stacks/messages as regular text? You can use triple back tick above and below for formatting. This makes it possible for search to find them |
Tagging subscribers to 'arch-android': @steveisok, @akoeplinger Issue DetailsDescriptionOn Android 11 release build, I was encountering System.Net.NetworkInformation.NetworkInformationException when called System.Net.NetworkInformation.NetworkInterface。GetAllNetworkInterfaces, and the error string is just success. I have added two permissions: INTERNET and ACCESS_NETWORK_STATE to which no avail. I think it's worth mentioning. I saw a log category named DOTNET_LINK so I reported the issue here. Reproduction StepsUsing System.Net namespace, call NetworkInterface.GetAllNetworkInterfaces Expected behaviorThe function completes with no exception Actual behaviorThe function throws System.Net.NetworkInformationException Regression?No response Known WorkaroundsNo response Configuration.NET 6.0.9 Other informationI skimmed through the PRs and there was a change to exclusively use the Xamarin's implementation of getifaddrs recently. But on Android 11 Google blocked NETLINK_ROUTE family socket from being bind. This is also the log that I was getting from adb I think it's correspond to this. I hope I'm right. One small note, I think this quirk is per vendor distribution, as my Xiaomi phone does not seems have this problem. Related issues about this blocking .
|
Here is the exception stack:
The log message I think to be related is this line. This is the only error line I found near this exception:
|
/cc @simonrozsival |
Another one suffering the issue here , this is what I see on logcat..
|
I started looking into the problem and as a quick workaround it is possible to modify <uses-sdk android:minSdkVersion="29" /> When the I'll keep working on a proper fix for this issue that will work with new SDKs. EDIT: The |
If anyone is looking for a workaround, without changing minSdkVersion and as @simonrozsival is suggesting with java bindings you can do something like this: public IList<IPAddress> GetAllLocalValidIp4Addresses()
{
#if ANDROID
// This is a workaround for this issue of MAUI on Android -> https://github.com/dotnet/runtime/issues/75809
// Instead of using regular .net we use Java Interop bindings directly.
var inetEnum = Java.Net.NetworkInterface.NetworkInterfaces;
if (inetEnum is null)
{
return new List<IPAddress>();
}
var ipAddresses = new List<IPAddress>();
foreach (var interfaces in Java.Util.Collections.List(inetEnum))
{
var addresses = (interfaces as Java.Net.NetworkInterface)?.InetAddresses;
if (addresses == null)
{
continue;
}
foreach (Java.Net.InetAddress address in Java.Util.Collections.List(addresses))
{
if (address.HostAddress == null || address.IsLoopbackAddress || address is not Java.Net.Inet4Address)
{
continue;
}
ipAddresses.Add(IPAddress.Parse(address.HostAddress));
}
}
return ipAddresses;
#else
#pragma warning disable CS8619 // This is not going to have any null, but the compiler is not able to determine it.
return NetworkInterface
.GetAllNetworkInterfaces()
.Where(n => n.OperationalStatus == OperationalStatus.Up)
.Where(n => n.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || n.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
.Where(n => !n.Description.ToLower().Contains("virtual"))
.Where(n => !n.Description.ToLower().Contains("pseudo"))
.SelectMany(n => n.GetIPProperties().UnicastAddresses)
.Where(n => n.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(g => g?.Address)
.Where(a => a != null) // Here I am checking to not adding anything null.
.ToList();
#pragma warning restore CS8619
#endif
} Sorry @simonrozsival I didn't noticed you're a developer of the project :D |
We are struggling with this issue as well, and we looking forward to a fix. Thank you for the work around - appreciated! |
I am on an issue with a project that uses a third party library ( sipsorcery ) which is .net 6, even setting minSdkVersion on my project my app still crashes as now the crash is into that library. I am checking how to patch it as it's opensource, but it's pure .net6 so not sure if I am going to be able to access Java.Net.NetworkInterface. It doesn't looks like that at first glance.. |
This produces a crash when using SipSorcery on Android devices, as the retrieval of all network interfaces creates an internal crash.
@simonrozsival I can see this has been back-ported to net7, but it also affects net6, and net7 isn't released yet. Can we get a back port to net6 please? |
I second that, we need net6 support. |
This was an oversight on my part as I only backported our change to .NET 7. I'll work to get this back to .NET 6. |
This produces a crash when using SipSorcery on Android devices, as the retrieval of all network interfaces creates an internal crash.
Description
On Android 11 release build, I was encountering System.Net.NetworkInformation.NetworkInformationException when called System.Net.NetworkInformation.NetworkInterface。GetAllNetworkInterfaces, and the error string is just success. I have added two permissions: INTERNET and ACCESS_NETWORK_STATE to which no avail. I think it's worth mentioning.
I saw a log category named DOTNET_LINK so I reported the issue here.
Reproduction Steps
Using System.Net namespace, call NetworkInterface.GetAllNetworkInterfaces
Expected behavior
The function completes with no exception
Actual behavior
The function throws System.Net.NetworkInformationException
Regression?
No response
Known Workarounds
No response
Configuration
.NET 6.0.9
Other information
I skimmed through the PRs and there was a change to exclusively use the Xamarin's implementation of getifaddrs recently. But on Android 11 Google blocked NETLINK_ROUTE family socket from being bind.
This is also the log that I was getting from adb
I think it's correspond to this. I hope I'm right.
One small note, I think this quirk is per vendor distribution, as my Xiaomi phone does not seems have this problem.
Related issues about this blocking .
The text was updated successfully, but these errors were encountered: