Vote count:
0
jni4net is a great tool and is working for me in most cases, but fails when calling .NET from Java using out and ref parameters. Note that passing parameters by value and returning a single return value works fine. The following code is greatly simplified and is intended simply to illustrate the problem -- please don't answer that out and ref parameters should not be used in this case and just return the result instead.
Environment:
- Windows 7 (64-bit)
- java version "1.7.0_71"
- Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
- Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
- jni4net version 0.8.8.0
C# code to be called
// a simple object to be used as a parameter
public class Simple
{
public int ID { get; set; }
public string Name { get; set; }
}
// this is the .NET class to be called from Java
public static class MyDotNetClass
{
public static void OutInt(out int value)
{
value = 999;
}
public static void RefInt(ref int value)
{
value = value + 1;
}
public static void OutString(out string value)
{
value = "out";
}
public static void RefString(ref string value)
{
value = value.ToUpper();
}
}
Java code which invokes the C# methods via jni4net...
If you attempt any of the following:
Out<String> out1 = null;
MyDotNetClass.OutString(out1);
OR
Out<Integer> outInt = null;
MyDotNetClass.OutInt(outInt);
OR
Out<Simple> outSimple3 = null;
MyDotNetClass.OutSimple(outSimple3);
You get an error message such as:
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006e9098d6, pid=7164, tid=3968
JRE version: Java(TM) SE Runtime Environment (7.0_71-b14) (build 1.7.0_71-b14) Java VM: Java HotSpot(TM) 64-Bit Server VM (24.71-b01 mixed mode windows-amd64 compressed oops) Problematic frame: V [jvm.dll+0x1398d6]
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as: C:\eclipse\workspace\myJavaTest\hs_err_pid7164.log
If you would like to submit a bug report, please visit:
http://ift.tt/19dgsTD
If you attempt the following:
Ref<String> refString1 = new Ref<String>("ref");
MyDotNetClass.RefString(refString1);
You get an error message such as:
Exception in thread "main" java.lang.IncompatibleClassChangeError at mydotnetassembly.MyDotNetClass.RefString(Native Method) at Program.main(Program.java:78) at net.sf.jni4net.jni.JNIEnv.ExceptionTest()(:0) at net.sf.jni4net.jni.JNIEnv.CallLongMethod()(:0) at net.sf.jni4net.inj.__IClrProxy.getClrHandle()(:0) at net.sf.jni4net.utils.Convertor.StrongJp2CString()(:0) at net.sf.jni4net.utils.Convertor.FullJ2C()(:0) at MyDotNetAssembly.__MyDotNetClass.RefString9()(:0)
However, if the ref parameter is an Integer or a simple C# object, it works:
Ref<Integer> refInt = new Ref<Integer>(1);
MyDotNetClass.RefInt(refInt);
Simple simple1 = new Simple();
simple1.setID(1);
simple1.setName("a");
Ref<Simple> refSimple1 = new Ref<Simple>(simple1);
MyDotNetClass.RefSimple(refSimple1);
id = simple1.getID();
name = simple1.getName();
Please let me know what needs to be done to successfully pass any out parameter or to successfully pass integers and strings as ref parameters. Thanks.
jni4net fails when calling .net from java using out and ref parameters
Aucun commentaire:
Enregistrer un commentaire