Skip to content

[netcore beta] Trying to export methods -> call them from Java - am I doing something wrong? #125

@DevSnobo

Description

@DevSnobo

Hello 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions