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;