Asp.net核心负载组件 [英] Asp.net Core Load Assembly
本文介绍了Asp.net核心负载组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图从文件夹中加载一些.dll文件:
I am tring to load some .dll files from a folder:
var fileNames = Directory
.GetFiles(path, "*.dll", searchOption);
var assemblyNames = fileNames
.Select(AssemblyLoadContext.GetAssemblyName);
List<Assembly> assemblies = new List<Assembly>();
foreach (AssemblyName assemblyName in assemblyNames)
{
assemblies.Add(Assembly.Load(assemblyName));
}
但是无法加载程序集:
FileNotFoundException,无法加载文件或程序集[...]系统找不到指定的文件。
But somehow the assembly cannot be loaded:
FileNotFoundException, Could not load file or assembly [...] The system cannot find the file specified.
这怎么可能,因为文件肯定存在?
How is this possible, because the file is definitely there?
如果您需要更多背景知识,我可以提供其他信息。
I can provide additional information, if you need more background.
推荐答案
使用以下using语句:
With these using statements:
using System.Reflection;
using System.Runtime.Loader;
尝试一下:
var myAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(pathTodll);
这篇关于Asp.net核心负载组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文