[英]FileLoadException while accessing assembly dlls in project application folder
I want to load assemblies stored inside my project application folder on the c:
drive. 我想加载存储在
c:
驱动器上的项目应用程序文件夹中的程序集。
This is the code: 这是代码:
public static void Main(string[] args)
{
Assembly asm = null;
asm = Assembly.LoadFrom("C:\\SampleProj\\Workspace\\Test_App\\bin\\Debug\\Assemblies");
}
The exception I am getting is: 我得到的例外是:
Could not load file or assembly 'file:///C:\\SampleProj\\Workspace\\Test_App\\bin\\Debug\\Assemblies' or one of its dependencies.
无法加载文件或程序集'file:/// C:\\ SampleProj \\ Workspace \\ Test_App \\ bin \\ Debug \\ Assemblies'或其依赖项之一。 Access is denied.
访问被拒绝。
I tried the following, but the error remains the same: 我尝试了以下操作,但错误仍然相同:
Please help. 请帮忙。
As I wrote in the comment, you are not specifying a valid path (you are specifying a folder when you need to specify a dll). 正如我在评论中所写,您未指定有效路径(当您需要指定dll时,您正在指定文件夹)。 If you want to load all the assemblies in that folder use this piece of code:
如果要加载该文件夹中的所有程序集,请使用以下代码:
private static List<Assembly> Assemblies = new List<Assembly>();
private static void LoadAllAssemblies(string path)
{
foreach (var dir in Directory.GetDirectories(path))
{
LoadAllAssemblies(Path.Combine(path, dir));
}
foreach (var file in Directory.GetFiles(path))
{
if (Path.GetExtension(file) == ".dll")
{
Assemblies.Add(Assembly.LoadFrom(Path.Combine(path, file)));
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.