You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Linux, IPInterfaceProperties.DnsAddresses throws PlatformNotSupportedException if /etc/resolv.conf is missing. This is incorrect. Per the man page, if the file does not exist (or has no nameserver lines) then the host acts as its own name server.
Reproduction Steps
On a Linux machine:
mv /etc/resolv.conf /etc/resolv.conf.backup
dotnet new console -o dnstest
cd dnstest
echo"using System.Net.NetworkInformation; Console.WriteLine(string.Join(' ', NetworkInterface.GetAllNetworkInterfaces().SelectMany(nic => nic.GetIPProperties().DnsAddresses)));"> Program.cs
dotnet run
Expected behavior
127.0.0.1 or 127.0.0.1 ::1
Alternately, blank might be considered correct depending on how you define the DnsAddresses property. That would be consistent with the case where /etc/resolv.conf has no nameserver lines, which presently produces an empty list. Or perhaps it should depend on whether the host actually has a DNS service running.
Alternately, document that PlatformNotSupportedException can be thrown if the DNS configuration is missing. Although I think InvalidOperationException is a better choice, since it's not really a platform-specific problem.
Regardless, the behavior when the file is missing should match the behavior when the file is empty.
Actual behavior
Unhandled exception. System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
at System.Net.NetworkInformation.UnixIPInterfaceProperties.get_DnsAddresses()
at Program.<>c.<<Main>$>b__0_0(NetworkInterface nic) in /home/mmorrison/dnstest/Program.cs:line 1
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.String.JoinCore[T](ReadOnlySpan`1 separator, IEnumerable`1 values)
at System.String.Join[T](Char separator, IEnumerable`1 values)
at Program.<Main>$(String[] args) in /home/mmorrison/dnstest/Program.cs:line 1
Regression?
No response
Known Workarounds
Catch the exception and treat it as an empty list.
Configuration
dotnet 6.0.135
Red Hat Enterprise Linux 8.10
x64
based on source code, the issue should apply to all Linux hosts
Other information
No response
The text was updated successfully, but these errors were encountered:
I think this is worth to fix, and also looks like a good candidate for community contribution. @wfurt do you agree? Any thoughts re returning 127.0.0.1 vs empty list?
Description
On Linux,
IPInterfaceProperties.DnsAddresses
throwsPlatformNotSupportedException
if /etc/resolv.conf is missing. This is incorrect. Per the man page, if the file does not exist (or has nonameserver
lines) then the host acts as its own name server.Reproduction Steps
On a Linux machine:
Expected behavior
127.0.0.1
or127.0.0.1 ::1
Alternately, blank might be considered correct depending on how you define the
DnsAddresses
property. That would be consistent with the case where /etc/resolv.conf has nonameserver
lines, which presently produces an empty list. Or perhaps it should depend on whether the host actually has a DNS service running.Alternately, document that
PlatformNotSupportedException
can be thrown if the DNS configuration is missing. Although I thinkInvalidOperationException
is a better choice, since it's not really a platform-specific problem.Regardless, the behavior when the file is missing should match the behavior when the file is empty.
Actual behavior
Regression?
No response
Known Workarounds
Catch the exception and treat it as an empty list.
Configuration
dotnet 6.0.135
Red Hat Enterprise Linux 8.10
x64
based on source code, the issue should apply to all Linux hosts
Other information
No response
The text was updated successfully, but these errors were encountered: