I am trying to call C# function from java using jni4net which work fine in windows 32 bit os however when I try to load same C# dll from a 64 bit OS am gettig this error
C:\Program Files (x86)\csharp\jni4net.n.w64.v20-0.8.6.0.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:47)
and here is my code
public class JNIFromC
{
private static String BRDIGE_INIT_URL="C:\\Program Files (x86)\\csharp\\jni4net.n.w64.v20-0.8.6.0.dll";
private static String JNI_URL="C:\\Program Files (x86)\\csharp\\csharp.j4n.dll";
public static void main(String[] args) {
Csharp cSharp=new getMyFunctionsFromCSharp();
}
public static Csharp getMyFunctionsFromCSharp() throws IOException {
Bridge.setClrVersion("v20");
Bridge.init(new File(BRDIGE_INIT_URL));
File shardFile = new File(JNI_URL);
Bridge.LoadAndRegisterAssemblyFrom(shardFile);
return new Csharp();
}
}
What could I be doing wrong
You need to compile your C# program with 32 bit flag. Or you could use corflags {my.exe} /32BIT+ /Force
. That would make your process to start as 32bit process.