Skip to content

NWPath crashes on EnumerateGateways #13772

@Immons

Description

@Immons

Steps to Reproduce

  1. Write code
  2. Start app
  3. Crash

Expected Behavior

Should work without problem and return gateways

Actual Behavior

System.InvalidCastException: Specified cast is not valid.
  at (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr)
  at ObjCRuntime.BlockLiteral.GetTarget[T] (System.IntPtr block) [0x0000b] in <5b08e01cb6df409eb2fea153e6177e5d>:0 
  at Network.NWPath.TrampolineEnumerator (System.IntPtr block, System.IntPtr iface) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Network/NWPath.cs:117 
  at (wrapper native-to-managed) Network.NWPath.TrampolineEnumerator(intptr,intptr)
  at (wrapper managed-to-native) Network.NWPath.nw_path_enumerate_gateways(intptr,ObjCRuntime.BlockLiteral&)
  at Network.NWPath.EnumerateGateways (System.Action`1[T] callback) [0x00023] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Network/NWPath.cs:201 
  at <project>.iOS.AppDelegate+<>c.<FinishedLaunching>b__2_0 (Network.NWPath path) [0x00001] in /Users/immons/Projects/<project>/AppDelegate.cs:66 
  at Network.NWPathMonitor.SetUpdatedSnapshotHandlerWrapper (Network.NWPath path) [0x0000f] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Network/NWPathMonitor.cs:135 
  at Network.NWPathMonitor.TrampolineUpdatedSnapshot (System.IntPtr block, System.IntPtr path) [0x00012] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Network/NWPathMonitor.cs:91 
  at (wrapper native-to-managed) Network.NWPathMonitor.TrampolineUpdatedSnapshot(intptr,intptr)
--- End of stack trace from previous location where exception was thrown ---

  at (wrapper managed-to-native) Network.NWPath.nw_path_enumerate_gateways(intptr,ObjCRuntime.BlockLiteral&)
  at Network.NWPath.EnumerateGateways (System.Action`1[T] callback) [0x00023] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Network/NWPath.cs:201 

Environment

=== Visual Studio Community 2019 for Mac ===

Version 8.10.16 (build 2)
Installation UUID: 09995ad3-84b8-4737-b130-b090e8f17c2d
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000162

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.162 (2020-02/2ca650f1f62) (64-bit)
	Package version: 612000162

=== Xamarin Designer ===

Version: 16.11.0.39
Hash: cd672761d
Branch: remotes/origin/d16-11
Build date: 2021-10-06 21:09:18 UTC

=== Roslyn (Language Service) ===

3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb

=== NuGet ===

Version: 5.9.0.7134

=== .NET SDK (x64) ===

SDK: /usr/local/share/dotnet/sdk/6.0.100/Sdks
SDK Versions:
	6.0.100
	5.0.404
	5.0.401
	5.0.301
	5.0.201
	5.0.103
	5.0.102
	5.0.101
	5.0.100
	3.1.416
	3.1.415
	3.1.413
	3.1.410
	3.1.407
	3.1.406
	3.1.405
	3.1.404
	3.1.403
	3.1.402
	3.1.401
	3.1.302
	3.1.300
	3.1.200
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	6.0.0
	5.0.13
	5.0.10
	5.0.7
	5.0.4
	5.0.3
	5.0.2
	5.0.1
	5.0.0
	3.1.22
	3.1.21
	3.1.19
	3.1.16
	3.1.13
	3.1.12
	3.1.11
	3.1.10
	3.1.9
	3.1.8
	3.1.7
	3.1.6
	3.1.4
	3.1.2
	2.1.23
	2.1.22
	2.1.21
	2.1.20
	2.1.18
	2.1.16

=== .NET Core 3.1 SDK ===

SDK: 3.1.416

=== .NET 5.0 SDK ===

SDK: 5.0.404

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 13.2.1 (19586)
Build 13C100

=== Xamarin.Mac ===

Version: 8.4.0.0 (Visual Studio Community)
Hash: 8fc41ae82
Branch: xcode13.2
Build date: 2021-12-09 01:07:56-0500

=== Xamarin.Android ===

Version: 12.0.0.3 (Visual Studio Community)
Commit: xamarin-android/d16-11/f0e3c2d
Android SDK: /Users/immons/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 31.0.3
SDK Build Tools Version: 30.0.3

Build Information: 
Mono: c633fe9
Java.Interop: xamarin/java.interop/d16-11@476bb5b
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.35.4@85460d3
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@87af37b

=== Eclipse Temurin JDK ===

Java SDK: Not Found

=== Android SDK Manager ===

Version: 16.10.0.13
Hash: 1b81df5
Branch: remotes/origin/d16-10
Build date: 2021-11-12 01:17:32 UTC

=== Android Device Manager ===

Version: 16.10.0.15
Hash: 89dcc0b
Branch: remotes/origin/d16-10
Build date: 2021-11-12 01:17:52 UTC

=== Xamarin.iOS ===

Version: 15.4.0.0 (Visual Studio Community)
Hash: 8fc41ae82
Branch: xcode13.2
Build date: 2021-12-09 01:07:56-0500

=== Build Information ===

Release ID: 810160002
Git revision: 6dbc7886fa608147f685a7df3912249400c84716
Build date: 2021-12-14 15:54:37-05
Build branch: release-8.10

=== Operating System ===

Mac OS X 11.4.0
Darwin 20.5.0 Darwin Kernel Version 20.5.0
    Sat May  8 05:10:33 PDT 2021
    root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

Example Project (If Possible)

var monitor = new NWPathMonitor(NWInterfaceType.Wifi);
monitor.SetQueue(DispatchQueue.DefaultGlobalQueue);
monitor.Start();
monitor.SnapshotHandler += path =>
{
//crashes
       path.EnumerateGateways(gateway =>
       {
           Console.WriteLine($"Gateway: {gateway}");
       });

       path.EnumerateInterfaces(intface =>
       {
           Console.WriteLine($"Interface: {intface}");
       });
};

Metadata

Metadata

Labels

bugIf an issue is a bug or a pull request a bug fix

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions