Skip to content
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

In Xamarin Forms, NetInterface.NetworkInterfaceType always return a value of 0 on Android. #76493

Closed
gceaser opened this issue Oct 1, 2022 · 4 comments · Fixed by #76370 or #76541
Closed

Comments

@gceaser
Copy link

gceaser commented Oct 1, 2022

Description

The same problem as documented in this ticket appears to be back.

#51303

netInterface.NetworkInterfaceType always return a value of 0 on Android. I am running on a OnePlust 7T with Android 11. This used to work fine. After one of the more recent updates, this issue seems to have been re-introduced.

Reproduction Steps

This is the exact code I am running:

            foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
                    netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    foreach (var addrInfo in netInterface.GetIPProperties().UnicastAddresses)
                    {

                        AvailableIPAddresses.Add(new IPObject() { IPAddress = (addrInfo.Address.AddressFamily == AddressFamily.InterNetworkV6 ? addrInfo.Address.ToString().Replace("%" + addrInfo.Address.ScopeId, "") : addrInfo.Address.ToString()), IPAddressType = addrInfo.Address.AddressFamily });


                        if (addrInfo.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            var ipAddress = addrInfo.Address;

                            // use ipAddress as needed ...
                        }
                    }
                }
            }

netInterface.NetworkInterfaceType always return a value of 0 on my Android device. I also upgraded to the latest Visual Studio update and the problem persists.

Expected behavior

The NetworkInterfaceType value should match up to one of the NetworkInterfaceType enums

Actual behavior

NetworkInterfaceType is always 0.

Regression?

Yes it worked in previous version of my Xamarin Forms application. I am not sure which update broke it.

Known Workarounds

No response

Configuration

Microsoft Visual Studio Professional 2022
Version 17.3.5
VisualStudio.17.Release/17.3.5+32922.545
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2022 00476-80000-00000-AA960
Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.3.376.3011
ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.3.376.3011
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.3.376.3011
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.3.20 (3f4cb00)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62207.04100
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.10701.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0
Information about my package

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin 17.3.0.308 (d17-3@56b9f7e)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.3.0.217 (remotes/origin/d17-3@b81db1dcc0)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.2.28 (9b3d244)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 13.0.0.0 (d17-3/030cd63)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: dffa5ab
Java.Interop: xamarin/java.interop@7716ae53
SQLite: xamarin/sqlite@df4deab
Xamarin.Android Tools: xamarin/xamarin-android-tools@14076a6

Xamarin.iOS and Xamarin.Mac SDK 16.0.0.75 (e4f48bed7)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Edition Windows 10 Pro for Workstations
Version 21H2
Installed on ‎9/‎4/‎2020
OS build 19044.2006
Serial number PF1QGPYV
Experience Windows Feature Experience Pack 120.2212.4180.0

Device name LenovoP72
Full device name LenovoP72.PSS1.com
Processor Intel(R) Xeon(R) E-2186M CPU @ 2.90GHz 2.90 GHz
Installed RAM 128 GB (128 GB usable)
Device ID 38040B9B-C3EB-420D-862E-728B9E08DB1A
Product ID 00391-70000-00000-AA046
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 1, 2022
@ghost
Copy link

ghost commented Oct 1, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

The same problem as documented in this ticket appears to be back.

#51303

netInterface.NetworkInterfaceType always return a value of 0 on Android. I am running on a OnePlust 7T with Android 11. This used to work fine. After one of the more recent updates, this issue seems to have been re-introduced.

Reproduction Steps

This is the exact code I am running:

        foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
                netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
            {
                foreach (var addrInfo in netInterface.GetIPProperties().UnicastAddresses)
                {

                    AvailableIPAddresses.Add(new IPObject() { IPAddress = (addrInfo.Address.AddressFamily == AddressFamily.InterNetworkV6 ? addrInfo.Address.ToString().Replace("%" + addrInfo.Address.ScopeId, "") : addrInfo.Address.ToString()), IPAddressType = addrInfo.Address.AddressFamily });


                    if (addrInfo.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        var ipAddress = addrInfo.Address;

                        // use ipAddress as needed ...
                    }
                }
            }
        }

netInterface.NetworkInterfaceType always return a value of 0 on my Android device. I also upgraded to the latest Visual Studio update and the problem persists.

Expected behavior

The NetworkInterfaceType value should match up to one of the NetworkInterfaceType enums

Actual behavior

NetworkInterfaceType is always 0.

Regression?

Yes it worked in previous version of my Xamarin Forms application. I am not sure which update broke it.

Known Workarounds

No response

Configuration

Microsoft Visual Studio Professional 2022
Version 17.3.5
VisualStudio.17.Release/17.3.5+32922.545
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2022 00476-80000-00000-AA960
Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.3.376.3011
ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.3.376.3011
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.3.376.3011
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.3.20 (3f4cb00)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62207.04100
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.10701.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0
Information about my package

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin 17.3.0.308 (d17-3@56b9f7e)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.3.0.217 (remotes/origin/d17-3@b81db1dcc0)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.2.28 (9b3d244)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 13.0.0.0 (d17-3/030cd63)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: dffa5ab
Java.Interop: xamarin/java.interop@7716ae53
SQLite: xamarin/sqlite@df4deab
Xamarin.Android Tools: xamarin/xamarin-android-tools@14076a6

Xamarin.iOS and Xamarin.Mac SDK 16.0.0.75 (e4f48bed7)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Edition Windows 10 Pro for Workstations
Version 21H2
Installed on ‎9/‎4/‎2020
OS build 19044.2006
Serial number PF1QGPYV
Experience Windows Feature Experience Pack 120.2212.4180.0

Device name LenovoP72
Full device name LenovoP72.PSS1.com
Processor Intel(R) Xeon(R) E-2186M CPU @ 2.90GHz 2.90 GHz
Installed RAM 128 GB (128 GB usable)
Device ID 38040B9B-C3EB-420D-862E-728B9E08DB1A
Product ID 00391-70000-00000-AA046
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display

Other information

No response

Author: gceaser
Assignees: -
Labels:

area-System.Net, os-android, untriaged

Milestone: -

@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Oct 2, 2022
@marek-safar marek-safar added this to the 7.0.x milestone Oct 2, 2022
@simonrozsival
Copy link
Member

This will be fixed by #76370

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 3, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Oct 3, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 2, 2022
@karelz
Copy link
Member

karelz commented Mar 22, 2023

Fixed in main (8.0) in PRs #76370 and #76541, and in 7.0 (RC2?) in PR #76565 and in 6.0.12 in PR #77260.

@karelz karelz modified the milestones: 7.0.x, 6.0.x Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.