Question

I realize there is a somewhat related thread on this here: Loading assemblies and its dependencies

But I am modifying something and this doesn't exactly apply.

string path = Path.GetDirectoryName( pathOfAssembly ); 
Environment.CurrentDirectory = path;
Assembly.Load(Path.GetFileNameWithoutExtension(pastOfAssembly));

Is there any really reason you would do it like this? Wouldn't it make more sense to just use:

Assembly.LoadFile(pathOfAssembly);

Any insight would be greatly appreciated.

Was it helpful?

Solution

Looks like the "Department of Redundancy Department."

A lot more code than is necessary. Less is more!

Edit: On second thought, it could be that the assembly you are loading has dependencies that live in its own folder that may be required to use the first assembly.

OTHER TIPS

This can be necessary when you are developping a windows service. The working dir of a service defaults to %WinDir%, so if you want to load an assembly from the dir that your service exe resides in, this is the way to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top