简体   繁体   English

jna / c#:java.lang.UnsatisfiedLinkError:查找函数“测试”时出错

[英]jna/c#: java.lang.UnsatisfiedLinkError: Error looking up function 'Test'

I would like to use a C# dll function. 我想使用C#dll函数。

c# C#

using RGiesecke.DllExport;

namespace dllExample
{
    public class DllExample
    {
        [RGiesecke.DllExport.DllExport]
        public static string Test(string id)
        {
            return "done" + id;
        }
    }
}

java 爪哇

@Test
public void jnaTest() {
    DllExample dllExample = Native.loadLibrary("c:\\Users\\IEUser\\RiderProjects\\dllExample\\dllExample\\bin\\Release\\RGiesecke.DllExport.Metadata.dll", DllExample.class);
    Assert.assertEquals("doneabc", dllExample.Test("abc"));
}

public interface DllExample extends Library{
    String Test(String id);
}

I build the c# project with Visual Studio and it makes 3 files into the project bin\\Release directory: 我使用Visual Studio构建了c#项目,它使3个文件进入了项目bin \\ Release目录:

  • dllExample.dll dllExample.dll
  • dllExample.pdb dllExample.pdb
  • RGiesecke.DllExport.Metadata.dll RGiesecke.DllExport.Metadata.dll

JDK version: 1.8.171 JDK版本:1.8.171

jna: net.java.dev.jna:jna:4.5.1 jna:net.java.dev.jna:jna:4.5.1

When the test is run, I get this exception: 运行测试时,出现以下异常:

java.lang.UnsatisfiedLinkError: Error looking up function 'Test': A megadott eljárás nem található. java.lang.UnsatisfiedLinkError:查找函数“ Test”时出错:megadotteljárásnemtalálható。

at com.sun.jna.Function.(Function.java:245) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:566) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:542) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:528) at com.sun.jna.Library$Handler.invoke(Library.java:228) at com.sun.proxy.$Proxy5.Test(Unknown Source) at hu.kdiv.keaesz.sign.DirectMSCAPITest.jnaTest(DirectMSCAPITest.java:149) 在com.sun.jna.Function。(Function.java:245)在com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:566)在com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:542) com.sun.proxy。$ Proxy5.Test上com.sun.jna.Library $ Handler.invoke(Library.java:228)上com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:528) ),网址为hu.kdiv.keaesz.sign.DirectMSCAPITest.jnaTest(DirectMSCAPITest.java:149)

What do I miss? 我想念什么? I was build the dll with Visual Studio Build Solution function. 我是用Visual Studio Build Solution函数来构建dll。

I was UnmanagedExpirt NuGet package. 我是UnmanagedExpirt NuGet软件包。 It is not good. 不好

Solution: 解:

Delete UnmanagedExport and use DllExport NuGet package. 删除UnmanagedExport并使用DllExport NuGet包。 Description here: https://github.com/3F/DllExport 此处描述: https//github.com/3F/DllExport

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM