Re: [jni4net] UnSatisfied Link Error while creating object

1,662 views
Skip to first unread message

Pavel Šavara

unread,
Jul 17, 2012, 4:02:16 AM7/17/12
to jni...@googlegroups.com
Most likely you forgot to call Bridge.LoadAndRegisterAssemblyFrom()

See
http://code.google.com/p/jni4net/source/browse/trunk/content/samples/myCSharpDemoCalc/MyCalcUsageInJava.java

On Tue, Jul 17, 2012 at 9:01 AM, Balaji <sbal...@gmail.com> wrote:
> Hi,
>
> I have written a C# code to add user in exchange distribution list. It
> works fine in .NET. Then I export the code to dll (ManageDL.dll) and used
> jni4net to generate proxies. It is crated ManageDL.j4n.dll. The class name
> in .NET is DistributionList and the constructor has 2 string params userid,
> password. When I tried to create an object in Java, it says UnsastifiedLink
> error while creating the object (__ctorDistributionList0). I have put all
> the necessary DLL and jar files in the project folder. Is there anyting I
> am missing?
>
> Thanks,
> Balaji
>
> --
> You received this message because you are subscribed to
> jni...@googlegroups.com
> http://groups.google.com/group/jni4net?hl=en-GB?hl=en-GB
> http://jni4net.sf.net/

Balaji

unread,
Jul 17, 2012, 6:34:45 AM7/17/12
to jni...@googlegroups.com
Yes I already did that.  Here is the code:

                Bridge.init();
Bridge.setDebug(true);
                Bridge.LoadAndRegisterAssemblyFrom(new File("ManageDL.j4n.dll"));
               DistributionList dList = new DistributionList("userid", "pwd");

And here is the error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: managedl.DistributionList.__ctorDistributionList0(Lnet/sf/jni4net/inj/IClrProxy;Ljava/lang/String;Ljava/lang/String;)V
at managedl.DistributionList.__ctorDistributionList0(Native Method)
at managedl.DistributionList.<init>(DistributionList.java:25)

Thanks,
Balaji

Jose Nuñez

unread,
Jul 17, 2012, 9:37:51 AM7/17/12
to jni...@googlegroups.com
are you sure your c# dll is working? are your dll methods public?
you can create a c# test app which calls the dll methods just to see
if your c# dll is ok.

it seems you are loading correctly the generated dll.

2012/7/17 Balaji <sbal...@gmail.com>:

Balaji

unread,
Jul 17, 2012, 3:23:07 PM7/17/12
to jni...@googlegroups.com
Hi,

All the methods are public and working fine in c# test application.

Thanks,
Balaji


On Tuesday, July 17, 2012 7:07:51 PM UTC+5:30, Jose Nuñez wrote:
are you sure your c# dll is working? are your dll methods public?
you can create a c# test app which calls the dll methods just to see
if your c# dll is ok.

it seems you are loading correctly the generated dll.

2012/7/17 Balaji

Balaji

unread,
Jul 17, 2012, 3:25:09 PM7/17/12
to jni...@googlegroups.com
Hi,

All the methods are public and works fine in c# test app.

Balaji Srinivasan

unread,
Dec 20, 2012, 6:16:58 AM12/20/12
to jni...@googlegroups.com
I am not using this API, instead I have created web services from .NET
and consumed from Java. It is very easy way than comparing with this
API and also Pavel has advised me to investigate the API and also how
to ask the questions to him.

On Wed, Dec 19, 2012 at 11:16 PM, Andy Hampshire
<andyst...@gmail.com> wrote:
> I don't suppose you resolved this ?
>
> I'm having the same problem with a DLL i've been given by a client and can't
> see what's wrong.
>
> It works fine from .Net but not from my Java class.
>
> any hints welcome ...
>
> Thanks .. .Andy

Andy Hampshire

unread,
Jan 9, 2013, 12:28:12 PM1/9/13
to jni...@googlegroups.com
At what point does it throw the error ?

The first time i built my wrapper i had the same problem ... second time round it seemed to just work and i don't understand why. My assumption is that it was a path/classpath type error.

Andy

On Wed, Jan 9, 2013 at 4:09 PM, Dirk Formhals <dirk.f...@googlemail.com> wrote:
Hi,
I'm having the same problem, reading post for hours, and cannot resolve the error. What I did:
 - I created a simple C# project (Visual C# Windows Dll) in Visual Studio 2012:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XWrapper
{
    public class Moveit
    {
        public static void moveTo(int station)
        {
            System.Console.Write("Hello world.");
        }
    }
}

I build the project and got a XWrapper.dll. Next, I called proxygen.exe with that DLL. It creates both a clr and jvm directory with this java class:

package xwrapper;

@net.sf.jni4net.attributes.ClrType
public class Moveit extends system.Object {
    
    //<generated-proxy>
    private static system.Type staticType;
    
    protected Moveit(net.sf.jni4net.inj.INJEnv __env, long __handle) {
            super(__env, __handle);
    }
    
    @net.sf.jni4net.attributes.ClrConstructor("()V")
    public Moveit() {
            super(((net.sf.jni4net.inj.INJEnv)(null)), 0);
        xwrapper.Moveit.__ctorMoveit0(this);
    }
    
    @net.sf.jni4net.attributes.ClrMethod("()V")
    private native static void __ctorMoveit0(net.sf.jni4net.inj.IClrProxy thiz);
    
    @net.sf.jni4net.attributes.ClrMethod("(I)V")
    public native static void moveTo(int station);
    
    public static system.Type typeof() {
        return xwrapper.Moveit.staticType;
    }
    
    private static void InitJNI(net.sf.jni4net.inj.INJEnv env, system.Type staticType) {
        xwrapper.Moveit.staticType = staticType;
    }
    //</generated-proxy>
}

There is a build.cmd also, so I used it and got a XWrapper.j4n.dll and a XWrapper.j4n.jar file. A Simple main to call the moveit(int) method is:

public static void main(String[] args) throws IOException {

        Bridge.init();
Bridge.setDebug(true);
Bridge.setVerbose(true);
        Bridge.LoadAndRegisterAssemblyFrom(new java.io.File("D:\\Daten\\VisualStudio\\jni4net\\work3\\XWrapper.j4n.dll"));

Moveit.moveTo(1);
        }

When running, the jni-DLLs are loading and I get the error:

java.lang.UnsatisfiedLinkError: xwrapper.Moveit.moveTo(I)V
        at xwrapper.Moveit.moveTo(Native Method)
        at ....main(StartXWrapper.java:40)

What can I do? Any idea? Thank you!

Dirk Formhals

unread,
Jan 9, 2013, 12:54:04 PM1/9/13
to jni...@googlegroups.com
The error occurres when I run the project. So the JVM/jni4net-DLLs  cannot load the Moveit class or find the moveTo method in that class. But, the proxygen.exe CAN LOAD the class, finds the moveTo method and generates correct proxy code :-(

I tried both jdk1.6 and jdk1.7 runtimes, and I tried to start it from the IDE (Netbeans) and in a command shell. When I remove the jni4net-DLLs I get a different error, so I am sure DLLs can be loaded.

Also, a system.Console.WriteLine("HelloWorld") runs without a problem - and as far as I understand this calls a .net runtime to write to the console. Is there a possibility to trace loading of DLLs? Or, after initializing the Bridge.LoadAndRegisterAssemblyFrom(file), to query the results of that?

Hmmm...

Stefan Falk

unread,
Sep 9, 2013, 4:12:49 AM9/9/13
to jni...@googlegroups.com


It is not the first time that I ask this question but I'm really stuck here a quiet long time because of this problem here. I am not familiar with JNI and it wouldn't be necessary if there wasn't this - to me - strange issue:

I made an Eclipse Plug-in that uses .dll-files which work on the .NET Framework. To do so I created a Java .NET Bridge using the jni4net framework which works so far but..

As I load my library from location A (the place where the plugin is developed)

File wrapperDll = new File("C:\\A\\SibKernel.Server.JavaWrapper.j4n.dll");

I can run the Eclipse Applicatoin ant everything works as it should. But if I load it from location B - which is just where my "standalone" Eclipse version is located

File wrapperDll = new File("C:\\B\\SibKernel.Server.JavaWrapper.j4n.dll");

this error occurs:

java.lang.UnsatisfiedLinkError: sibkernel.server.sp40javawrapper.SP40Device.__ctorSP40Device0(Lnet/sf/jni4net/inj/IClrProxy;)V
    at sibkernel.server.sp40javawrapper.SP40Device.__ctorSP40Device0(Native Method)
    at sibkernel.server.sp40javawrapper.SP40Device.<init>(SP40Device.java:25)
    at sibeclipseplugin.debug.model.SP40Program.<init>(SP40Program.java:46)
    at sibeclipseplugin.debug.model.SibDebugTarget.<init>(SibDebugTarget.java:67)
    at sibeclipseplugin.ui.launch.LaunchConfigurationDelegate.launch(LaunchConfigurationDelegate.java:26)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:858)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1018)
    at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1222)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Laurent Cohen

unread,
Nov 18, 2014, 4:13:59 AM11/18/14
to jni...@googlegroups.com
I know this is a little late given the start of htis thread, but I was recently facing the same issue and discovered why it occurred in my setup.
At some point, I decided to add "Bridge.setDebug(true);" and "Bridge.setVerbose(true);" to my code, in the hope I would get additional clues on this UnsatisfiedLinkError. From the additional traces, I realized that the jni4net dll and my own generated dlls were not loaded from the same folder. So loading the dlls with Bridge.LoadAndRegisterAssemblyFrom() didn't raise any exception, but when trying to instantiate a Java object generated from a C# class, there was this UnsatisfiedLinkError.

After making sure that all dlls were loaded from the same folder, the error disappeared. I hope this hint will help others with the same problem.

-Laurent

Sean Hou

unread,
Nov 27, 2014, 12:35:05 AM11/27/14
to jni...@googlegroups.com
You are right!

The jni4net core(jni4net.n-0.8.8.0.dll) and *.j4n.dll must be located in one single place. Otherwise there will be an error...

在 2014年11月18日星期二UTC+8下午5时13分59秒,Laurent Cohen写道:

Joos Kiener

unread,
Jul 15, 2015, 1:31:16 AM7/15/15
to jni...@googlegroups.com
I also had this issue and was able to resolve it by putting everything, meaning jars AND dlls in the same folder. I go an UnsatisfiedLinkError if all dlls where in the same place but not the jars.

My code:

 System.setProperty( "java.library.path", "libs" ); // libs contains all dlls and jars
//...
¨Bridge.LoadAndRegisterAssemblyFrom(new File("libs/xxxx.j4n.dll"));

RAJESH KUMAR

unread,
Sep 14, 2015, 3:54:31 AM9/14/15
to jni4net

Hi Joos Kiener,

The following error i am facing in my eclipse environment.Is this error resolved for you.added all dll files in same folder and not jar files.jar files added to build path of project.
Please help me if you resolve this problem.
loading core from D:/Rajesh/JNI4NET/jni4net.n-0.8.8.0.dll
loading jni4net.n-0.8.8.0, Version=0.8.8.0, Culture=neutral, PublicKeyToken=134a23405600bab4 from D:\Rajesh\JNI4NET\jni4net.n-0.8.8.0.dll
loaded jni4net.n-0.8.8.0, Version=0.8.8.0, Culture=neutral, PublicKeyToken=134a23405600bab4 from D:\Rajesh\JNI4NET\jni4net.n-0.8.8.0.dll
Initialized jni4net core
core loaded from D:/Rajesh/JNI4NET/jni4net.n-0.8.8.0.dll
clr.version         :v4.0.30319
clr.arch            :32bit
java.home           :C:\Program Files\Java\jre7
java.version        :1.7.0_79
sun.arch.data.model :32
loading SampleDll.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\BhushanProg\SabreWork\Jni4Net\SampleDll.j4n.dll
loaded SampleDll.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\BhushanProg\SabreWork\Jni4Net\SampleDll.j4n.dll
Exception in thread "main" java.lang.UnsatisfiedLinkError: sampledll.Sample.__ctorSample0(Lnet/sf/jni4net/inj/IClrProxy;)V
at sampledll.Sample.__ctorSample0(Native Method)
at sampledll.Sample.<init>(Sample.java:25)
at Jni4NetTest.main(Jni4NetTest.java:22)

Thanks,
P Rajesh Kumar,

RAJESH KUMAR

unread,
Sep 15, 2015, 3:06:00 AM9/15/15
to jni4net

Hi to all,
I am unable to execute using eclipse but execute the code from command prompt from windows.

Steps :
1.Created proxy files(using vb.net dll (SimpleDll.dll))
2. write java program.(Jni4NetTest.java)
3. copy proxy files and jar files in one folder
4.compile the java program
Ex:-
D:\Rajesh\jni4net>javac -d .\ -cp .\jni4net-0.8.8.0.jar;.\SimpleDll.j4n.jar Jni4NetTest.java

5.Run the java program
Ex:-
D:\Rajesh\jni4net>java -cp jni4net-0.8.8.0.jar;SimpleDll.j4n.jar;. Jni4NetTest

Please help me and thanks in advance


P Rajesh Kumar.

Jni4Test.jpg

RAJESH KUMAR

unread,
Sep 15, 2015, 6:24:43 AM9/15/15
to jni4net

Hi all,

Now able to execute my eclipse application followed by this video link.
https://www.youtube.com/watch?v=tI0tFUjeffA (Using Jni4Net) from 25:14 mins onwards.

Thanks&Regrads,
P Rajesh Kumar

Poornima Bajaj

unread,
Jul 18, 2019, 2:27:35 AM7/18/19
to jni4net
Hello Rajesh,

I exactly have the same problem, class is loaded but getting unsatisfiedlinkerror when calling the function.
I tried to listen to the video mentioned below, but could not understand what the author spoke at 35:07, where the actual solution of the problem is.
He removed a jar and then added back another jar. What is the difference. Which jar should be added.
Please reply. It's urgent. Thanks in advance.
Reply all
Reply to author
Forward
0 new messages