【问题标题】:Unable to find an entry point named 'JoinString' in DLL 'Dll.dll'. in C#无法在 DLL“Dll.dll”中找到名为“JoinString”的入口点。在 C# 中
【发布时间】:2018-07-07 04:27:55
【问题描述】:

我在 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'.

【问题讨论】:

    标签: c# dll dllimport


    【解决方案1】:

    根据 MSDN:

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

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

    【讨论】:

    • 我必须使用它 DLL 导入。那么如何更改为非托管代码?
    • C# 是完全托管的代码。您必须用 C++ 或 C 编写此库才能使用 DllImportAttirbute。请参阅以下线程:stackoverflow.com/questions/8043545/… 似乎有一种解决方法,但我从来不需要这样做,也无法提供可靠的答案。您必须使用 DllImport 的原因是什么?
    • 因为我的 dll 每周都会更改。所以使用 dllimport 我可以替换新的 dll。
    • 您只需将 DLL 替换到位,它就会被使用。此外,无需为自己的 dll 使用 nuget,只需添加对项目或原始 dll 的引用即可。
    • 只要您没有强烈命名您的程序集,那么您只需替换为较新的版本,并且只要该类存在于命名空间中并且方法都向后兼容,那么一切都会正常工作。 MEF 或反射在这里绝对是矫枉过正。
    猜你喜欢
    • 2011-04-14
    • 1970-01-01
    • 2021-08-05
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多