为什么汇编类不在c#中运行? [英] Why assembly class not run in c#?

查看:67
本文介绍了为什么汇编类不在c#中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

Hi, This is my code:

        private void form_Load(object sender, EventArgs e)
        {
 string s = Directory.GetCurrentDirectory()+@"\plugin";
            Assembly assembly = Assembly.LoadFrom(s);
            AssemblyName assemblyn = assembly.GetName();
            MessageBox.Show(assemblyn.ToString());
}



当我追踪我的程序时,第2行以后的代码将无法运行!!

我反复更改但是与Assembly类相关的代码不会运行,也不允许后续代码运行!



来自评论:我想加载我的dll目录中的文件没有使用这些名称,另一方面我不知道dll文件的名称。


When i trace my program the code in line 2 onwards will not run!!
I change it repeatedly but the code that related to Assembly class will not run and does not allow to subsequent code run also!

From comment: I want load my dll files from directory without use these names, in other hand i dont know the name of dll files.

推荐答案

你需要提供完整的路径和文件名 Assembly.LoadFrom(..) [ ^ ],例如:

You need to provide the full path and file name to Assembly.LoadFrom(..)[^], e.g.:
Assembly assembly = Assembly.LoadFrom(@"c:\test\MyAssembly.dll");



但是你只提供了一条路径(或者,如果插件是名称对于该文件,您必须附加.dll或者,不太可能,但.exe)。



评论后编辑:



要从特定目录加载所有程序集,可以使用 Directory.EnumerateFiles(..) [ ^ ]从目录中检索所有(匹配)文件,然后遍历 IEnumerable< string> ; -result逐个加载它们。 (链接的页面有示例代码。)


But you only provided a path (or, if "plugin" is the name of the file, you have to append ".dll" or, unlikely but possible, ".exe").

Edit after comment:

To load all assemblies from a specific directory, you can use Directory.EnumerateFiles(..)[^] to retrieve all (matching) files from the directory and then loop over the IEnumerable<string>-result to load them one by one. (The linked page has a sample code.)


这篇关于为什么汇编类不在c#中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆