Error CS1729 when using NWPath in MAUI iOS project.

Mameshiba 20 Reputation points
2023-08-22T08:35:55.54+00:00
Hello,

If I use the NWPath class as new
There is no constructor that specifies 2 arguments (Error CS1729).
Is there any workaround?


<Err Souce code>

public Test(IntPtr handle, bool owns)
{
	NWPath npath = new NWPath(handle, owns) ;	 // Compiler Error CS1729
}


Visual Studio pro 2022
Version:17.7.1
Project:C# 



---------------------------------------------
There is no constructor that specifies 2 arguments
 public NWPath(IntPtr handle, bool owns);


<NWPath.cs>

// C:\Program Files\dotnet\packs\Microsoft.iOS.Ref\16.4.7089\ref\net7.0\Microsoft.iOS.dll
#endregion

#nullable enable

using CoreFoundation;
using ObjCRuntime;
using System;
using System.ComponentModel;
using System.Runtime.Versioning;

namespace Network
{
	[SupportedOSPlatform("tvos12.0")]
	[SupportedOSPlatform("macos")]
	[SupportedOSPlatform("ios12.0")]
	[SupportedOSPlatform("maccatalyst")]
	public class NWPath : NativeObject
	{
		public NWPathStatus Status { get; }
		public bool IsExpensive { get; }
		public bool HasIPV4 { get; }
		public bool HasIPV6 { get; }
		public bool HasDns { get; }
		public NWEndpoint? EffectiveLocalEndpoint { get; }
		public NWEndpoint? EffectiveRemoteEndpoint { get; }
		[SupportedOSPlatform("tvos13.0")]
		[SupportedOSPlatform("macos10.15")]
		[SupportedOSPlatform("ios13.0")]
		[SupportedOSPlatform("maccatalyst")]
		public bool IsConstrained { get; }

		[EditorBrowsable(EditorBrowsableState.Never)]
		[Obsolete("Use the overload that takes a 'Func<NWEndpoint, bool>' instead.")]
		[SupportedOSPlatform("tvos13.0")]
		[SupportedOSPlatform("macos10.15")]
		[SupportedOSPlatform("ios13.0")]
		[SupportedOSPlatform("maccatalyst")]
		public void EnumerateGateways(Action<NWEndpoint> callback);
		[BindingImpl(BindingImplOptions.Optimizable)]
		[SupportedOSPlatform("tvos13.0")]
		[SupportedOSPlatform("macos10.15")]
		[SupportedOSPlatform("ios13.0")]
		[SupportedOSPlatform("maccatalyst")]
		public void EnumerateGateways(Func<NWEndpoint, bool> callback);
		[EditorBrowsable(EditorBrowsableState.Never)]
		[Obsolete("Use the overload that takes a 'Func<NWInterface, bool>' instead.")]
		public void EnumerateInterfaces(Action<NWInterface> callback);
		[BindingImpl(BindingImplOptions.Optimizable)]
		public void EnumerateInterfaces(Func<NWInterface, bool> callback);
		public bool EqualsTo(NWPath other);
		[SupportedOSPlatform("ios14.2")]
		[SupportedOSPlatform("tvos14.2")]
		[SupportedOSPlatform("macos11.0")]
		[SupportedOSPlatform("maccatalyst14.2")]
		public NWPathUnsatisfiedReason GetUnsatisfiedReason();
		public bool UsesInterfaceType(NWInterfaceType type);
	}
}


---------------------------------------------

Best Regards,
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,072 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leo Wagner de Souza 696 Reputation points
    2023-08-22T10:18:59.07+00:00

    Hello @Mameshiba !

    What exactly are you trying to do?

    Please note that NWPath is a internal object, and should not be created by the user:
    https://learn.microsoft.com/en-us/dotnet/api/networkextension.nwpath.-ctor?view=xamarin-ios-sdk-12

    Did you tried to use the MAUI Connectivity class instead?
    https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/communication/networking?tabs=android

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.