How do I get the path of the assembly the code is in?

Posted by Ramesh Singh | Updated on

If you want to get the path of the assembly the code is in? Use the below c# example code. I’ve defined the following property as we use this often in unit testing.

The Assembly.Location property sometimes gives you some funny results when using NUnit (where assemblies run from a temporary folder), so I prefer to use CodeBase which gives you the path in URI format, then UriBuild.UnescapeDataString removes the File:// at the beginning, and GetDirectoryName changes it to the normal windows format.
Reference


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers