Could not create an native instance in Xamarin.IOS

49 views Asked by At

I am trying to bind native Swift library to my Xamarin IOS project (I use VS on MAC). I followed the guide: https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough I did everything as mentioned util the "Consume the binding library" step. When I try to create an instance of my ProxyFramework inside my project: var proxy = new SwiftFrameworkProxy();

I get an error when deploying: Could not create an native instance of the type 'NativeLibrary.SwiftFrameworkProxy': the native class hasn't been loaded.

I have 3 .xcframework files generated from source repository (I generate them with Carthage), I included all of them in my "NativeReferences". Also I included reference to my ProxyFramework.xcframework to Native references in my Ios Binding Library. In all references I used the following properties (same as in guide): .xcframework Properties

My binding library looks like this: Ios Binding Library project

The only thing I changed in comparison with the guide is I added [Protocol] Attribute to the SwiftFrameworkProxy interface in ApiDefinitions.cs. Without the [Protocol] I got error: undefined Objective-C class: SwiftFrameworkProxy. The symbol '_OBJC_CLASS_$_SwiftFrameworkProxy' could not be found in any of the libraries or frameworks linked So now the interface looks like:

[BaseType(typeof(NSObject))] [Protocol] interface SwiftFrameworkProxy

I tried to change LinkWithAttribute params, like ForceLoad, SmartLink, etc, nothing worked

0

There are 0 answers