无法在 DLL"Dll.dll"中找到名为 'JoinString' 的入口点。在 C# 中



我在 c# 中创建了一个 dll,如此方法所示:

namespace Dll
{
public class Check
{
public string JoinString(string fristName, string Lastname)
{
return fristName + " " + Lastname;
}
}
}

我构建了这个DLL,我想在另一个应用程序中使用它DLLImport,如下所示:

[DllImport("Dll.dll", EntryPoint = "JoinString")]
public static extern string JoinString (string fristName, string Lastname);
private void button1_Click(object sender, EventArgs e)
{
string s = JoinString("aaa", "bbbb");
MessageBox.Show(s.ToString());

}

但是我收到此错误:

An unhandled exception of type 'System.EntryPointNotFoundException' occurred in WindowsFormsApplication3.exe
Additional information: Unable to find an entry point named 'JoinString' in DLL 'Dll.dll'.

根据 MSDN:

DllImportAttribute:指示特性化方法由非托管动态链接库 (DLL( 作为静态入口点公开。

您的 DLL 命名空间似乎是用托管代码 C# 编写的。这将导致托管 dll。相反,您应该添加对 dll 项目的引用,或者利用 nuget 将 dll 安装到其他项目中。

最新更新