Comments, how-to's, examples, tools, techniques and other material regarding .NET and related technologies.
Saturday, September 05, 2009
Path used in Assembly.LoadFrom()
One way of loading an assembly into an AppDomain is using the static method Assembly.LoadFrom(). An interesting aspect here is: Which folder is used when you supply a relative path?
You might be seduced to believing that it will use AppDomain.CurrentDomain.BaseDirectory and combine that with the relative path. That's, however, not correct.
Instead it is using Environment.CurrentDirectory, which can be an entirely different directory than the AppDomain's base directory! The online documentation states that it is using "the current directory" but this might still be misleading as it doesn't necessarily make the reader aware that this is different from AppDomain.CurrentDomain.BaseDirectory.
Therefore, if you want to be on the safe side construct an absolute path, e.g. by using Path.Combine() etc. Also consider that the location from where you (down)load might actually be an URL.
Labels:
Technology
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
All comments, questions and other feedback is much appreciated. Thank you!