title: How can I convert Assembly.CodeBase into a filesystem path in C#?
body: <p>I have a project that stores templates in a <code>\Templates</code> folder next to the DLLs and EXE.</p>
  
  <p>I want to determine this file path at runtime, but using a technique that will work inside a unit test as well as in production (and I don't want to disable shadow-copying in NUnit!)</p>
  
  <p><code>Assembly.Location</code> is no good because it returns the shadow-copied assembly's path when running under NUnit.</p>
  
  <p><code>Environment.CommandLine</code> is also of limited use because in NUnit et al it returns the path to NUnit, not to my project.</p>
  
  <p><code>Assembly.CodeBase</code> looks promising, but it's a UNC path:</p>
  
  <pre><code>file:///D:/projects/MyApp/MyApp/bin/debug/MyApp.exe
  </code></pre>
  
  <p>Now I <em>could</em> turn this into a local filesystem path using string manipulation, but I suspect there's a cleaner way of doing it buried in the .NET framework somewhere. Anyone know a recommended way of doing this?</p>
  
  <p>(Throwing an exception if the UNC path is not a <code>file:///</code> URL is absolutely fine in this context)</p>