Assembly.CodeBase: when is it no file-URI?
Posted
by Marc Wittke
on Stack Overflow
See other posts from Stack Overflow
or by Marc Wittke
Published on 2009-10-23T09:28:33Z
Indexed on
2010/05/07
7:28 UTC
Read the original article
Hit count: 302
Assembly.Location gives a plain path to the assembly. Unfortunately this is empty when running in a shadowed environment, such as unit test or ASP.NET. Hovever, the Codebase property is available and provides a URI that can be used instead. In which cases it returns no URI starting with file:///
? Or in other words: what are the cases in which this won't work or will return unusable results?
Assembly assembly = GetType().Assembly;
Uri codeBaseUri = new Uri(assembly.CodeBase);
string path = codeBaseUri.LocalPath;
© Stack Overflow or respective owner