I have an executable, say abc.exe, which references a.dll (same folder as executable), b.dll (in random folder), and c.dll (in random folder).
However, these DLLs are not necessarily in the same directory as the executable (or in the GAC), and that’s something I cannot do anything about.
I’ve tried to use System.Reflection.Assembly to try to find all the referenced assemblies used by abc.exe.
foreach (AssemblyName an in assembly.GetReferencedAssemblies())
{
Assembly.Load(an);
}
This seems to load the assemblies that are in the executable’s directory (a.dll), but not surprisingly throws file not found exceptions for the others.
My idea is to load the process using System.Diagnostics.Process and then reflect on the process, since that should tell me where to find b.dll and c.dll(?)
However, I don’t know how to go about doing so. Is this possible, and if so, how can it be done? Thanks!
So it turns out this can be done with System.Diagnostic.Process, e.g.:
Where ModuleName gives you the name of the assembly and FileName gives you the correct assembly path, regardless of where it is (On the network, in C:\Windows, etc.)
However, I cannot figure out how to ‘detect’ when an executable has finished loading all the modules. If I remove the sleep line, I see only a partial list of modules, which I guess are the ones that are done loading by the time process.Modules is called.