A community member has associated this post with a similar question:
GeList(out IntPtr variableName) send null values for out parameter from the iOS Binding dll in .NET 8

Only moderators can edit this content.

.NET MAUI application method returning null IntPtr when migrated from .NET 7 to .NET 8

Gunawardana, Bagya Nuwanthi 0 Reputation points

Recently we have migrated our Xamarin Bindings and Xamarin app to support .NET MAUI with .NET 7. So now we have iOS Binding and .NET MAUI App. As our iOS native SDK is written in Objective-C, it has the below method which requires a pointer variable.

-(RESULT)getItemList:(NSMutableArray **)itemList { }

So to generate the binding we have below definition for the above method in ApiDefinition file in the iOS binding library.

Result GetItemList(out IntPtr itemList);

In our MAUI app which supports .NET 7 we are successfully passing the handle of the NSMutableArray and getting the itemList with the below implementation.

NSMutableArray itemList = new NSMutableArray(); 
IntPtr handle = itemList.Handle;  
Result result = iOSSdk.GetItemList(out handle);  
itemList = ObjCRuntime.Runtime.GetNSObject<NSMutableArray>(handle);

But when we migrated to .NET 8 the IntPtr handle is returning null. According to .NET MAUI migration document https://learn.microsoft.com/en-us/dotnet/maui/migration/ios-binding-projects?view=net-maui-8.0  we tried changing the IntPtr in to ObjCRuntime.NativeHandle also. Then also the handle is null. What changes need to be made to make this work in .NET 8 which was previously working fine with .NET 7?

Microsoft Technologies based on the .NET software framework.
3,364 questions
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,857 questions
0 comments No comments
{count} votes