When I run unit tests with Visual Studio it works fine, because it runs from project directory where all assemblies are. But when I run it with resharper it
Just to complete the very helpful answer from mcdon, using assembly.Location gives the correct answer as per MSFT's explanation:
The CodeBase is a URL to the place where the file was found, while the Location is the path from where it was actually loaded. For example, if the assembly was downloaded from the internet, its CodeBase may start with “http://”, but its Location may start with “C:\”. If the file was shadow copied, the Location would be the path to the copy of the file in the shadow-copy dir.
It’s also good to know that the CodeBase is not guaranteed to be set for assemblies in the GAC. Location will always be set for assemblies loaded from disk, however.
Therefore I would use the following:
public static DirectoryInfo GetAssemblyDirectory()
{
var assembly = Assembly.GetExecutingAssembly();
return new DirectoryInfo(Path.GetDirectoryName(assembly.Location));
}