How to find out where Assembly.Load(String) would load an assembly from without actually doing it?
This is the question:
I want to know where the assembly will be loaded from, but I don't want to actually load it. Can I do that? How?
If you read my previous post, you will already know the answer is NO. In general you can’t find out where the assembly will be loaded unless you load it.
Of course this does not prevent you from making a well educated guess based on the documented fusion probing behavior. But this guess won't be accurate all the time.
Or we can ask the question the other way:
Why do you need to know that?
Can you achieve your goal with alternative ways?
Comments
- Anonymous
May 17, 2005
Unless trickery is involved, you would usually get the assembly from AppBasePath or PrivateBinPath,etc.
So that should be enough for most of it. - Anonymous
May 18, 2005
The comment has been removed - Anonymous
May 18, 2005
Well, how about my GAC API Managed Wrapper?
Sample Managed GAC API Wrappers
http://blogs.msdn.com/junfeng/articles/229649.aspx
Specifically, QueryAssemblyInfo. - Anonymous
May 22, 2005
> Why do you need to know that?
Oh that's easy to answer. Or maybe only easy to nearly-answer, but here are two very very near-answers.
1. Why did Raymond Chen blog about a way to do Unix's "which" command in Windows? Was it because 30 years of experience with the "which" command in Unix showed how useless it was? Or because it is useful?
2. There are some important programs that run under Windows and inspect the contents of ordinary executable files in sandboxes before letting the ordinary executable files actually run. - Anonymous
May 22, 2005
Norman,
Looking for exes is very static. The OS simply looks at the directories listed in %PATH% environment variable.
Now imagine this:
There is a switch. When the switch is turned on, the OS will look at some other places instead of %PATH%.
Ok. There are more switches. When they are turned on the OS will do something different.
Even the exe is not found in %PATH%, you can say I want the OS to try something else.
Now how much "which" is useful? - Anonymous
May 23, 2005
It seems to me that the importance of the "which" command multiplies by a huge factor in that kind of situation.
By the way this means a real "which" command not just one that looks at %PATH%. For example competent "which" commands on Unix look at aliases and other possible settings besides just $PATH, in order to report what the shell (or OS in your case) will really do. - Anonymous
May 23, 2005
The problem is those factors are unknown until runtime. There is really nothing you can do.