views:

514

answers:

2

I realize there is a somewhat related thread on this here: http://stackoverflow.com/questions/22012/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.

+3  A: 

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.

benPearce
This is exactly why they did it...thanks
Adam Driscoll
If this answer is correct, maybe a vote for it?
benPearce
A: 

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.

Treb