When I load a native shared library with "JavaSystem.Load()" in a static
constructor like this:

  class MyClass {
    static MyClass() {
      Java.Lang.JavaSystem.Load("/path/to/libmylib.so");
    }

    [DllImport("mylib")]
    private static extern int get_version();

    public static int getVersion() {
      return get_version();
    }
  }

Why do the following code fail (with DllNotFoundException)?

  int x = MyClass.getVersion();

But this code (instead) succeeds:
  
  var unused = new MyClass();
  int x = MyClass.getVersion();

Note that in each case the class MyClass is encountered for the first time
(i.e. the static constructor hasn't been executed before). 

Also note that "JavaSystem.Load()" succeeds, so the library gets loaded
correctly. (Otherwise the second code example wouldn't work either.)

I've attached an example project: 
http://mono-for-android.1047100.n5.nabble.com/file/n5710852/LibLoadFailTest.zip
LibLoadFailTest.zip 

--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/P-Invoke-fails-with-JavaSystem-Load-in-static-constructor-bug-tp5710852.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to