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屋!
查看全文