private static string GetExecutablePath()
{
Assembly asm = Assembly.GetExecutingAssembly();
// Assembly. EscapedCodeBase имеет вид file://c:\SomeFolder\Assembly.dll
// Используем свойство EscapedCodeBase вместо свойства CodeBase чтобы
// символ # (и подобные ему) был бы представлен как %23 и не приводил
// к исключению в конструкторе Uri
// Класс Url позволяет преобразовывать file:// ссылки в локальный путь
// с помощью свойства LocalPath
return new Uri(asm.EscapedCodeBase).LocalPath;
}