Bug 11497 - “The native class hasn't been loading” error with my bindings.
Summary: “The native class hasn't been loading” error with my bindings.
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-04-01 03:54 UTC by folex
Modified: 2015-05-06 05:58 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

7z with 2 projects in it: TryingBindings -- bindings themselves; TryingGPUImage -- bindings in use; (693.44 KB, application/x-7z-compressed)
2013-04-01 03:54 UTC, folex
Build output (22.22 KB, text/plain)
2013-04-01 09:07 UTC, folex
Build output of project that uses bindings. (3.55 KB, text/plain)
2013-04-01 09:16 UTC, folex
Binding & Sample project (196.30 KB, application/octet-stream)
2015-05-06 05:58 UTC, supreet

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description folex 2013-04-01 03:54:27 UTC
Created attachment 3725 [details]
7z with 2 projects in it: TryingBindings -- bindings themselves; TryingGPUImage -- bindings in use;

I'm trying to create bindings for GPUImage project (https://github.com/BradLarson/GPUImage/blob/master/framework/Source), but none of binded classes is working. For example, GPUImageView:
In ObjC it's declared like this (https://github.com/BradLarson/GPUImage/blob/master/framework/Source/GPUImageView.h):

    @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))]
        interface GPUImageInput {

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


    [assembly: LinkWith ("libGPUImage.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, 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: http://pastie.org/7160314
After I set MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false GPUImageView was created, but unusable.

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

Thanks in advance.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-04-01 08:40:37 UTC
This is most likely a build problem.

Can you add "-v -v -v" (without the quotes) to the additional mtouch arguments in the project's iOS Build options page, clean, rebuild and attach the full build output?
Comment 2 folex 2013-04-01 09:07:17 UTC
Created attachment 3727 [details]
Build output
Comment 3 folex 2013-04-01 09:16:05 UTC
Created attachment 3728 [details]
Build output of project that uses bindings.

It's strange for that verbose level, but there is very little amount of output.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2013-04-01 09:23:56 UTC
This looks strange, it's as if the binding library is treated like a normal library instead of a binding library.

Can you attach your binding library too?
Comment 5 folex 2013-04-01 09:47:59 UTC
You mean .a file? It's already attached: look into TryingBindings project in 7z file.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2013-04-01 10:13:22 UTC
Sorry, I didn't see you had already attached your projects.

There are two problems:

1) The file with the LinkWith attribute (libGPUImage.linkwith.cs) is not compiled. Just right-click the TryingBindings project, Add, Add files and select it.

2) The native library does not contain code for i386 (simulator), only arm (device). If you're building the native library yourself you can either create a universal library that contain code for all the architectures, or you can use several native libraries, each supporting a different set of architectures, and just have a LinkWith attribute for each native library.
Comment 7 folex 2013-04-02 02:18:40 UTC
Thanks a lot! 
Would you mind explaining how did you find out that libGPUImage.linkwith.cs wasn't compiled?
Comment 8 Rolf Bjarne Kvinge [MSFT] 2013-04-02 08:10:00 UTC
It was immediately obvious when I opened the binding project (I've seen quite a few binding projects, so it stood out).
Comment 9 supreet 2015-05-06 05:58:35 UTC
Created attachment 11084 [details]
Binding & Sample project

I am facing the same issue. 

This is the native library that I am trying to bind 

I've followed Rolf's comments & added the linkwith.cs back to the project to make sure it compiles. 
Attached are the binding & sample projects. 
Any help is appreciated.