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

Unable to find an entry point named 'JoinString' in DLL 'Dll.dll'. in 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: Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.

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