Hello,
Welcome to our Microsoft Q&A platform!
[__NSDictionaryM setObject:forKey:]: object cannot be nil means that inserting nil into NSDictionary caused a crash, NSDictionary
in Objective-C does not support nil as a key or value.
NSDictionary
is used in two places:
var options = new NSDictionary<NSString, NSObject>((NSString)NSObject.FromObject("activationAttemptId"), NSObject.FromObject(activationAttemptId));
protocolConfiguration.ProviderConfiguration = new NSDictionary<NSString, NSObject>();
Howerver, I can't reproduce the issue, I also change NSDictionary
to NSMutableDictionary
, the demo doesn't crash. You could check if NSDictionary
is used in other places and make a breakpoint to determine which line of the code caused this crash. I suspect that something went wrong when you modified Info.plist and Entitlement.plist file,because there are also Dictionary
in these two files , you could check it.
Another Issue
It adds value for key com.apple.developer.networking.networkextension as packet-tunnel instead of packet-tunnel-provider.
When you work with Network Extensions
, packet-tunnel
will be added, my VS for Mac version is 8.10.10 . For more information, you can refer to
https://learn.microsoft.com/en-us/xamarin/ios/deploy-test/provisioning/capabilities/?tabs=macos
------Update-----
About permission denied
this issue, you need to check the APP bundle and profile, this doc shows how to work with Capabilities in Xamarin.iOS
- Go to Appledeveloper portal
- Select Identifiers => App IDs
- Select your app
- Click edit button, check the
network-extension
checkbox
My Test
using NetworkExtension;
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
test();
//test1();
return base.FinishedLaunching(app, options);
}
public void test()
{
var activationAttemptId = new NSUuid().AsString() + "-SECRET-VPN";
Console.WriteLine("Activation UUID " + activationAttemptId);
var options = new NSMutableDictionary<NSString, NSObject>((NSString)NSObject.FromObject("activationAttemptId"), NSObject.FromObject(activationAttemptId));
Console.WriteLine("options " + options);
}
public void test1()
{
var tunnelProviderManager = new NETunnelProviderManager();
tunnelProviderManager.LocalizedDescription = "Second Xam VPN";
var protocolConfiguration = new NETunnelProviderProtocol();
protocolConfiguration.ProviderBundleIdentifier = "xxx.xxx";
protocolConfiguration.ServerAddress = "XXX:XXX";
protocolConfiguration.ProviderConfiguration = new NSDictionary<NSString, NSObject>();
tunnelProviderManager.ProtocolConfiguration = protocolConfiguration;
tunnelProviderManager.Enabled = true;
tunnelProviderManager.SaveToPreferences((NSError error) => {// ...logic here .....
//
});
}
}
Make sure check NetworkExtensions
in VS, and provisioning profile is right.
Best Regards,
Wenyan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.