Some classes from binding are not loaded on iOS simulators

sumeetdevidansumeetdevidan USMember
edited November 2016 in Xamarin.iOS

I get the following error when trying to access a certain objective C class from my native library :

System.Exception: Could not create an native instance of the type 'NameSpace.CustomClass': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.

I have looked up this error and found that there is an issue if we dont compile iOS native library for simulators.
But I compile my iOS native code for all architectures and combine them to one fat libLibrary.a file. I use this fat library in binding ObjC to C# via the binding process that Xamarin provides.

I am able to access most of the classes i need via the binding process, the exception happens only for a few classes on simulators. I cant figure out why would only a few classes would throw this exception while other classes/interfaces are working flawlessly. All the classes I need are available in the ApiDefiniton.cs file and checked multiple times for correct binding syntax.

I also checked the "libLibrary-sim.a" (i.e the build for simulator) library to check if the class I am getting error for are included in it via the following command :
"nm libLibrary-sim.a"

And also checked in the final fat library, the class/object exist in both the libraries. It just doesnt load at runtime.

Simulator build command :
xcodebuild -project Demo.xcodeproj -target $1 -sdk iphonesimulator -configuration Release clean build GCC_PREPROCESSOR_DEFINITIONS="XAMARIN_SUPPORT=1" | tail -n 2

Combine to fat lib :

lipo -create -output lib$1.a lib$1-arm64.a lib$1-armv7s.a lib$1-armv7.a lib$1-sim.a

Xamarin linking :

using ObjCRuntime;

[assembly: LinkWith ("libLibrary.a", LinkTarget.ArmV7s | LinkTarget.ArmV7 | LinkTarget.Simulator | LinkTarget.Simulator64 | LinkTarget.Arm64,Frameworks="CoreFoundation CoreGraphics CoreLocation Foundation QuartzCore UIKit SystemConfiguration CoreText CoreTelephony Security QuickLook", LinkerFlags = "-lz -lsqlite3", SmartLink = true, ForceLoad = false, IsCxx = true)]

1. The linker class i.e libLibrary.linkwith.cs is included and compiled in the binding project.
2. The problematic class has "init" method hidden in Objc to make a singleton, but even making "init" method available doesnt help.

Can someone please help. Have been stuck on this for days now.
Thanks in advance.

Sign In or Register to comment.