Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How could i write code that load all dll:s from a subdirectory below the current directory?
And also do this?

// In each loaded dll, look for classes implementing IOffer
Posted
Comments
[no name] 18-Jul-14 18:21pm    
LoadAssembly and Reflection.
George Jonsson 18-Jul-14 21:56pm    
Is it Win32 DLL's or .NET assemblies?

1 solution

Assemby.LoadFile methood:

C#
string[] files = Directory.GetFiles("c:\program", "*.dll");
foreach (var file in files)
{
  var assembly = Assembly.LoadFile(file);
  var types = assembly.GetTypes();
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Jul-14 12:37pm    
In most cases, Assembly.LoadFrom is more adequate. Read MSDN help pages to see the difference.
Also, I am sure that you understand that after "var types" lines the types should be used somehow, but some naive readers may not get it, so you would need to explain it. Otherwise the objects referenced by the variables "assembly" and "types" will be simply lost in each iteration.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900