Reputation: 1
I want to load assemblies stored inside my project application folder on the c:
drive.
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. Access is denied.
I tried the following, but the error remains the same:
Please help.
Upvotes: 0
Views: 172
Reputation: 1567
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). 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)));
}
}
}
Upvotes: 1