But now I have found by chance a much better solution, which is more robust and also useful for other shadow copying scenarios like hosting WCF services in IIS. You can use the assemblies CodeBase property to get the original location. The only drawback is that the codebase is formatted as a Uri. It normally includes a file protocol “file:///” and uses slashes ‘/’ instead of backslashes ‘\’, so you need to modify the returned string a bit:
var assembly = Assembly.GetExecutingAssembly();
var path = assembly.CodeBase.Replace("file:///", "").Replace("/", "\\");
var path = assembly.CodeBase.Replace("file:///", "").Replace("/", "\\");
I have used this too for a while but after updating from VS2010/ReSharper6.1 to VS2012/Resharper7.1 it seems like CodeBase is pointing to the new path.
ReplyDeleteDo any one know a fix for that?