locked
"The native class hasn't been loading" error with my bindings. RRS feed

  • Question

  • User7202 posted

    I'm trying to create bindings for GPUImage project, but none of binded classes is working. For example, GPUImageView: In ObjC it's declared like this:

    @interface GPUImageView : UIView <GPUImageInput>
    //then some fields, properties and methods I'm not interested in
    

    So, my ApiDefinition.cs looks like this:

    namespace GPUImage
    {
        [BaseType (typeof(NSObject))]
        [Model]
        interface GPUImageInput {
        }
    
        [BaseType (typeof(UIView))]
        interface GPUImageView : GPUImageInput {
            [Export ("initWithFrame:")]
            IntPtr Constructor(RectangleF frame);
        }
    }
    

    LinkWithAttributes:

    [assembly: LinkWith ("libGPUImage.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, "-ObjC", ForceLoad = true, Frameworks = "CoreMedia CoreVideo OpenGLES QuartzCore AVFoundation UIKit Foundation")]
    

    It builds ok and creates dll. But when I try to use it in my project like this:

    var iv = new GPUImageView (new RectangleF (0, 0, 100, 100));
    

    Exception throwed:

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

    Stacktrace

    After MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure == false iv was created, but unusable (e.g. AddSubview(iv) show nothing).

    I suppose there is something wrong with GPUImage.a file, but I don't know how to test it in any way.

    There is 2 projects in attached 7z: TryingBindings -- bindings themselves; TryingGPUImage -- bindings in use;

    Thanks in advance.

    Friday, March 29, 2013 10:53 AM

All replies

  • User39 posted

    Just for future reference: this was responded to and solved here: https://bugzilla.xamarin.com/show_bug.cgi?id=11497

    Monday, April 1, 2013 10:13 PM
  • User58922 posted

    Hi @RolfBjarneKvingef I am also facing the same issue. I tried adding the linkwith.cs file back to the binding project to make sure it compiles but there is no difference in the output. I've attached my binding & sample projects in the Bugzilla Issue https://bugzilla.xamarin.com/show_bug.cgi?id=11497

    Could you please take a look & point me in right direction? Thanks

    Wednesday, May 6, 2015 10:02 AM
  • User16951 posted

    I am having the same issue. I tried to use -v -v -v and found out that my .a file was compiled for Simulator64 (iPhone 6 simulator) and I was trying to run test project on Simulator (iPhone 4 simulator)

    I fixed that (by running test app on iPhone 6) so I have no warnings but the app is crashing with the same exception.

    Thursday, August 13, 2015 5:04 PM
  • User16951 posted

    Problem was solved by providing a fat .a file with all platforms included. I was not able to make bindings work with only one platform included inside .a file.

    Thursday, August 13, 2015 5:19 PM
  • User75709 posted

    @AlexS : Did you resolve the error? I'm facing the same error with one binding and stuck on the error.

    Monday, June 12, 2017 8:27 PM
  • User16951 posted

    @SagarPanwala yes, by having an .a file with all platforms in it.

    Tuesday, June 13, 2017 2:14 AM
  • User75709 posted

    @AlexS : Thanks, I followed a link https://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial but it is failing. So can you please guide me how you did?

    Tuesday, June 13, 2017 5:16 AM
  • User75709 posted

    @AlexS : I resolved this issue, but now it is showing me this error in other libraries also. I didn't updated the Xamarin or Xcode in past couple of months. This was working fine last week then stopped suddenly.

    Any one know , why these errors are showing suddenly and was working fine earlier? Please please help me to resolve this error.

    Tuesday, June 13, 2017 6:49 PM
  • User16951 posted

    What are these errors? It is hard to help when it is unclear what is the specific error and actions you take.

    Tuesday, June 13, 2017 11:55 PM
  • User329165 posted

    AlexS what you mean by having an .a file with all platforms in it. which plattaforms? please help i'm having the same issue in IOS project, as you can see i followed all the instrucciotions to create the IOS binding from Objective C library, i can read all the methods of the library created but the native error issue is still showing up, do i need to create a folder scructure adding the .a file in xamarin ios project?

    Monday, June 26, 2017 9:42 PM
  • User21936 posted

    @pepeluche

    I responded to your other post here: https://forums.xamarin.com/discussion/comment/282919/#Comment_282919

    I cover how to see what architectures your native library (.a file) is built for in that post.

    Tuesday, June 27, 2017 1:00 AM
  • User329165 posted

    hi JGoldberger , thank you for you information about xamarin binding objetive c libraries i followed your instrucctions, and these are my steps:

    1.in the main solution of the project i created a binding ios project and add mi libeposlin.a file(generated following the instrucctions of walkthough , objetive c documentation for xamarin , once i do that it creates automatically a libeposlin.a.cs file with build action ObjcBindingNativeLibrary the code: using System; using ObjCRuntime;

    [assembly: LinkWith("libepsonlib.a", LinkTarget.ArmV7 | LinkTarget.Simulator | LinkTarget.Simulator64, ForceLoad = true, SmartLink = true, LinkerFlags = "-ObjC -all_load -fobjc-arc")]

    2.After compile the binding project it was succesfully, so i added the .dll reference in the ios xamarin form project and it can be added properly , also i added in the ios project in the native references area the same libeposlib.a and i change some properties(as you can say in the image attached).

    3.i rebuild, i using some of the native code of epson in order to work, everuthing works fine, but the error still persist

    i'm wondering if i have to add some code in the addictional argument of mtoch in build option of ios project

    are going in the right direction?

    Thursday, June 29, 2017 6:56 PM
  • User272135 posted

    @pepeluche What library are you binding? I can take a look at the library if you need any assistance. A lib.a.cs file is deprecated and there should be a Native References folder.

    Thursday, June 29, 2017 7:22 PM
  • User329165 posted

    hi , the librarie i tried to binding in IOS is ePOS2.h and easyselect.h they are including epson native sdk(libeposeasyselect.a and libepos2.a) they are epson libraries to print in epson printers https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=5457&scat=58&pcat=52

    i followed all the steps here https://developer.xamarin.com/guides/ios/advancedtopics/bindingobjective-c/walkthrough/ i created a .a library with objective c sample program, i add the .a file generated with architecture ArmV7,ArmV7s,x66 as the manual says using Command Line tools in xcode, then in xamarin studio i create the binding of the file and it creates the linkwith.cs automatically, i added the architetures requited using System; using ObjCRuntime; [assembly: LinkWith("libepsonlib.a", LinkTarget.ArmV7 | LinkTarget.Simulator | LinkTarget.Simulator64 | LinkTarget.ArmV7s, SmartLink = true, ForceLoad = true, LinkerFlags = "-lsqlite3.0 -lc++")]

    then in a blank ios project i make a reference to the .dll generated in the binding, all the methods/properties of epson were added in appidefinition.cs(in the binding) then run the ios project and call to an epson method , the error still persists.

    Thursday, June 29, 2017 8:30 PM
  • User329165 posted

    what you mean A lib.a.cs file is deprecated? do i have to add the .a file in the native references instead to adding in the root folder of the binding?

    Thursday, June 29, 2017 9:44 PM
  • User272135 posted

    Yes you have to add the .a file to the Native References now, though the old method should still work. After you add it to the native references folder you right click the file and edit its files. I'll take a look at the library in a sec.

    Thursday, June 29, 2017 10:01 PM
  • User329165 posted

    Thank you NasZhou, i already fixed, now it is working.

    https://forums.xamarin.com/discussion/comment/283839#Comment_283839

    Friday, June 30, 2017 4:48 PM