question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetworkInterface.GetAllNetworkInterfaces() on Android leads to FileNotFoundException ('/etc/resolv.conf')

See original GitHub issue

Description

Hi,

we tried to port our Xamarin.Forms app to MAUI and encountered a bug.

When calling System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() we get an FileNotFoundException On Windows this works.

image

Callstack {System.Net.NetworkInformation.NetworkInformationException (0x80004005): Success at System.Net.NetworkInformation.LinuxNetworkInterface.GetLinuxNetworkInterfaces() at System.Net.NetworkInformation.NetworkInterfacePal.GetAllNetworkInterfaces() at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() at Busmonitor.MAUI.MainPageViewModel.Discover() in C:\git\Busmonitor\Busmonitor.MAUI\ViewModels\MainPageViewModel.cs:line 70}

Best regards

Steps to Reproduce

  1. In MAUI Template add NetworkInterface.GetAllNetworkInterfaces() to Button Handler
  2. On Executing the code a file System.IO.FileNotFoundException: ‘Could not find file ‘/etc/resolv.conf’.’ get thrown

Version with bug

Preview 10 (current)

Last version that worked well

Preview 10 (current)

Affected platforms

Android

Affected platform versions

Android 10

Did you find any workaround?

no

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dos-isecommented, Jan 2, 2022

https://github.com/dotnet/runtime/pull/62780

This seems to fix the problem when merged.

0reactions
dos-isecommented, Dec 3, 2021

After looking at the code you linked I think there is no way this code could ever run on android. The implementation completely relies on parsing the resolv.conf file. Which is not available on android. I think this it is also not available on some linux distros and I am not sure if this is available on iOS.

[https://github.com/dotnet/runtime/blob/b201a16e1a642f9532c8ea4e42d23af8f4484a36/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs#L56]

The mono implementation on the other hand seems much better here. [https://github.com/mono/mono/blob/bdd772531d379b4e78593587d15113c37edd4a64/mcs/class/System/System.Net.NetworkInformation/LinuxNetworkInterface.cs#L64]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Last version of MongoDB.Driver not working for Android 8+
When i try to read data from server i get Exeption: Error resolving name servers (Object reference not set to an instance of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found