[netcore beta] Trying to export methods -> call them from Java - am I doing something wrong?
See original GitHub issueHello there, I’m still hoping that I’m just doing something wrong when configuring the solution, but I’m not making any progress.
I have a student project where I shall implement some kind of plugin system to integrate .NET into a monolithic Java product. After implementing a prototype with RGiesecke’s nuget package, it somehow broke (not finding il(d)asm.exe anymore) and I’m now trying to implement the same thing with your extended solution - and targeting netcore instead of framework.
Problem:
When trying to execute a C# method from Java, there’s an Invalid memory access
error.
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:426)
at com.sun.jna.Function.invoke(Function.java:361)
at com.sun.jna.Library$Handler.invoke(Library.java:265)
at com.sun.proxy.$Proxy0.Test(Unknown Source)
at bla.bli.blub.dlltest.DllTest.main(DllTest.java:14)
When my configuration still worked with RGiesecke’s package, the setup below worked (though, target was framework). Now when trying to do this with your extension for netcore projects, there seems to be a problem. I tried to provide all the info I have to reproduce this issue below and also attached the projects here: Lib.zip JavaExample.zip
If you need more information, please let me know.
Now to my code:
C# .NET Core Library project (“Lib”)
namespace Lib
{
public class LibClass
{
[DllExport]
public static int Test(int input)
{
return 40 + input;
}
}
}
Java Maven project
import com.sun.jna.Library;
import com.sun.jna.Native;
public class DllTest {
public static void main(String[] args) {
ILib libClass = Native.load(
"path\\to\\project\\Testing\\Lib\\bin\\x64\\Debug\\netcoreapp3.0\\Lib",
ILib.class);
int result = libClass.Test(2);
System.out.println(result);
}
public interface ILib extends Library {
public int Test(int input);
}
}
with the Maven dependency
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
</dependency>
Steps to configure the solution:
- add nuget package (1.7-beta) to C# project
- place DllExport.bat into solution folder
- execute command "DllExport.bat -action Configure"
- check the project "Lib\Lib.csproj"
- select "x64" radio button
- check "PE Check IL code"
- check "Use our IL Assembler (...)"
The other values were left on their defaults.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Well, the problem due to incorrect processing in my coreclr IL Assembler and more like others official MS versions that implements resolving of System.Private.CoreLib on the assembly stage for the PE module.
This is what I’m talking about, in #90 I already voiced about various base for system Object and this is it:
As we can see, the correct number is 0x0006 (I mean, of course, only current assembly above) because AssemblyRef encoded into the low 2 bits of the number due to ECMA-335:
In general, I confirm the bug.
We need to fix related processing in IL Assembler for our DllExport. I’ll try to fix this week, maybe next. More probably I already know where to look this part of logic. Follow the news.
Please test applied solution through latest beta releases.