runtime icon indicating copy to clipboard operation
runtime copied to clipboard

NetworkInterface.GetAllNetworkInterfaces throws on UWP

Open clairernovotny opened this issue 10 years ago • 38 comments

I’m using the “final” .NET Core bits off of the MyGet feed and ran into an issue trying to use System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(). The method throws on UWP with a NotImplementedException.

    System.Net.NetworkInformation.dll!System.Net.NetworkInformation.NetNativeNetworkInterface.GetNetworkInterfaces()    Unknown
    System.Net.NetworkInformation.dll!System.Net.NetworkInformation.NetworkInterfacePal.GetAllNetworkInterfaces()   Unknown
    System.Net.NetworkInformation.dll!System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()  Unknown
>   Zeroconf.dll!Zeroconf.NetworkInterface.NetworkRequestAsync(byte[] requestBytes, System.TimeSpan scanTime, int retries, int retryDelayMilliseconds, System.Action<string, byte[]> onResponse, System.Threading.CancellationToken cancellationToken) Line 28  C#
    Zeroconf.dll!Zeroconf.ZeroconfResolver.ResolveInternal(System.Collections.Generic.IEnumerable<string> protocols, byte[] requestBytes, System.TimeSpan scanTime, int retries, int retryDelayMilliseconds, System.Action<string, Heijden.DNS.Response> callback, System.Threading.CancellationToken cancellationToken) Line 75    C#
    Zeroconf.dll!Zeroconf.ZeroconfResolver.BrowseDomainsAsync(System.TimeSpan scanTime, int retries, int retryDelayMilliseconds, System.Action<string, string> callback, System.Threading.CancellationToken cancellationToken) Line 113 C#
    ZeroconfTest.UWP.exe!ZeroconfTest.UWP.MainPage.ResolveClick(object sender, Windows.UI.Xaml.RoutedEventArgs e) Line 25   C#

Why isn’t this working on UWP? The library has explicit support for netcore50 in the 4.1.0 nuget package. I would not expect arbitrary methods to simply not work. It sort of undermines trust that WYSIWYG when it comes to available surface area.

clairernovotny avatar Jun 25 '16 02:06 clairernovotny

cc: @joshfree @stephentoub @CIPop @himadrisarkar @ericstj

Those particular methods are unimplemented right now. We plan to add the rest of the support later this year in an update to the System.Net.NetworkInformation package.

davidsh avatar Jun 25 '16 03:06 davidsh

Is there a document that lists out which methods are known not to be implemented per OS/platform along with plans for future support across all of CoreFX?

It'd be far more helpful to reference this in advance than during testing and discovering these things.

clairernovotny avatar Jun 25 '16 12:06 clairernovotny

@davidsh can you provide the full list of System.Net APIs that throw on UWP? These need to be added to @leecow's release notes for Monday morning

joshfree avatar Jun 25 '16 21:06 joshfree

To be clear, my request is across all of corefx if there are other areas where this may come up.

Thanks!

clairernovotny avatar Jun 25 '16 21:06 clairernovotny

Those particular methods are unimplemented right now. We plan to add the rest of the support later this year in an update to the System.Net.NetworkInformation package.

@davidsh Any ETA on this? This is particularly confusing since the official .NET Core documentation lists these methods as implemented and documented. Frankly, I don't think they should be even listed there until they actually are in the framework...

nadimkobeissi avatar Aug 10 '16 10:08 nadimkobeissi

cc: @himadrisarkar

Himadri will look into the documentation to see why it is out of sync with the code implementation.

davidsh avatar Aug 10 '16 17:08 davidsh

I don't think they should be even listed there until they actually are in the framework...

+1

@davidsh, @himadrisarkar @joshfree These APIs exist to support the netstandard surface but will throw on run-time. There are others that do the same. I believe we have previously done an analysis and came up with a list that now needs to be integrated within the documentation.

@onovotny to work-around this missing functionality please use Windows.Networking.Connectivity. Here are a few related classes that might get you the information you need:

  • https://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.aspx
  • https://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectionprofile.aspx
  • https://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkadapter.aspx

CIPop avatar Aug 10 '16 18:08 CIPop

@CIPop This alternative API not solve the problems with libraries which supports the netstandard.

Horcrux7 avatar Aug 10 '16 20:08 Horcrux7

@CIPop This alternative API not solve the problems with libraries which supports the netstandard.

I acknowledge that: it's a complicated workaround for those libraries to work on UWP until we get the APIs implemented.

CIPop avatar Aug 10 '16 21:08 CIPop

Just a comment: .NET Core and that whole family of new and open .NET efforts are really promising and cool, but the framework needs to be communicated and organized in a far more coherent way than it is now.

nadimkobeissi avatar Aug 11 '16 09:08 nadimkobeissi

Hi everybody! I just spend a good two days looking for a way to retrieve the subnetmask of my network adapters, for now no luck. Each "solution" I found point to the not implemented method System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()...

My question now is, did anybody here figured out a way to get the subnetmask of the available interfaces?

thx, bg

ChristophvanderFecht avatar Nov 23 '16 10:11 ChristophvanderFecht

Create C\C++ Runtime Component and use GetAdaptersAddresses. https://msdn.microsoft.com/en-us/library/windows/apps/aa365915.aspx

Available since Anniversary.

jtoivola avatar Nov 23 '16 20:11 jtoivola

@jtoivola Thx for the suggestion. I also found that currently you can only get the information by using native code. I will have a look at this.

Yesterday I used this PInvoke as mentioned on Stackoverflow. It solved the problem for me.

ChristophvanderFecht avatar Nov 24 '16 06:11 ChristophvanderFecht

These APIs exist to support the netstandard surface but will throw on run-time. There are others that do the same

This is an absolutely horrible practice. That completely defeats the purpose of having a .NET Standard.

dotMorten avatar Feb 15 '17 00:02 dotMorten

@karelz will this be included in the work to get netstandard 2.0 to UWP? Like actually implemented and working, not throwing?

clairernovotny avatar Feb 15 '17 01:02 clairernovotny

We should at minimum consider it. Personally I'd say that if it is implementable (via APIs available in UWP context) and not super-costly, I don't see a reason to exclude it - @davidsh @CIPop is it part of your NS2.0 UWP plan?

Note: The issue is marked 'untriaged' - we are still working through Networking area triage (it's taking longer than I'd like as we are heads down on quite a lot of high-pri Netwroking issues :().

cc: @geoffkizer @Priya91

BTW: It would help if we can see upvotes on the top post to capture customer impact/interest. 10+ votes will be something hard to ignore ;-)

karelz avatar Feb 15 '17 01:02 karelz

@davidsh @CIPop is it part of your NS2.0 UWP plan?

yes, this is already part of our .NET Standard 2.0 for UWP plan.

And by the way, the implementation won't be using WinRT APIs for UWP. We plan to re-use the existing .NET Core implementation which will work on UWP since those needed win32 api's will be part of allowed api for app container.

davidsh avatar Feb 15 '17 01:02 davidsh

@davidsh That's fantastic news! From the above comments, it sounded like there might be other API's in a similar situation -- that are in the surface area but throw at runtime on UWP. Is that still the case for 2.0 or have those gaps been filled? If there will still be a gap, is there a list we can triage to help get community support behind any specific sections?

clairernovotny avatar Feb 15 '17 01:02 clairernovotny

@karelz What would be the milestone for .netstandard2.0 UWP? Leaving it at Future for now.

Priya91 avatar Feb 15 '17 01:02 Priya91

@Priya91 very good point. I think it's time to create one - I'll call it 2.1-UWP for now (@danmosemsft feel free to adjusted while I am OOF :))

karelz avatar Feb 15 '17 01:02 karelz