There are two methods to get assembly path:
Method 1:
Assembly asm = Assembly.GetAssembly(this.GetType());
string path = asm.Location;
string folderPath = Path.GetDirectoryName(path);
Method 2:
Assembly asm = Assembly.GetAssembly(this.GetType());
string codeBase = asm.CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
string folderPath = Path.GetDirectoryName(path);
As simplicity of Method1 wins over Method2 when NUnit test is not required because Method1 fails sometime during NUnit test.
0 Comment(s)