简体   繁体   中英

Assembly.Load and Environment.CurrentDirectory

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM