且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么汇编类不在c#中运行?

更新时间:2023-11-13 23:25:04

你需要提供完整的路径和文件名 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&gt ; -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.)