Skip to content

GetAllNetworkInterfaces throws on Success on Android .NET 6 #77938

@Bip901

Description

@Bip901

Description

When calling System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces, instead of returning the result, a System.Net.NetworkInformation.NetworkInformationException is thrown with a message of 'Success'.

Reproduction Steps

MainActivity.cs:

namespace Test1
{
    [Activity(Label = "@string/app_name", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle? savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            var interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
        }
    }
}

csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <RootNamespace>Test1</RootNamespace>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ApplicationId>com.example.test1</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  </PropertyGroup>
</Project>

Expected behavior

A list of network interfaces is returned, like on Windows.

Actual behavior

The method call throws the following exception:

System.Net.NetworkInformation.NetworkInformationException (0x80004005): Success   at System.Net.NetworkInformation.NetworkInterfacePal.TransformNetworkInterfacess[AndroidNetworkInterface[]](Func`5 transform)   at System.Net.NetworkInformation.NetworkInterfacePal.GetAndroidNetworkInterfaces()   at System.Net.NetworkInformation.NetworkInterfacePal.GetAllNetworkInterfaces()   at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()   at LAN_Direct_Android.MainActivity.OnCreate(Bundle savedInstanceState) in D:\Ori\CSharp\LAN Direct\LAN Direct Android\MainActivity.cs:line 12   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-31/mcw/Android.App.Activity.cs:line 2781   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121

Regression?

Used to work in Xamarin.Android (Mono)

Known Workarounds

No response

Configuration

.NET 6 on Android x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions