Note that there are some explanatory texts on larger screens.

plurals
  1. PODetermine application executing directory on server or client
    primarykey
    data
    text
    <p>Here is my problem. I want to load libraries into my application at runtime. This will allow the application to consume new implementations of an interface without needing re-compilation. The application will search its own directory for the libraries. I have code that achieves this:</p> <pre><code> var path = Assembly.GetExecutingAssembly().Location; path = Path.GetDirectoryName(path); path = Path.Combine(path, "&lt;my assembly&gt;.dll"); var assembly = Assembly.LoadFile(path); </code></pre> <p>This code works perfectly in a unit test. However, the application is a web application. When I run this code as part of the application, <code>Assembly.GetExecutingAssembly().Location</code> returns a temporary directory within the .net framework. (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\...) I could probably fix this by using <code>Server.MapPath</code>, but then the code won't be unit testable anymore.</p> <p>I'd really like to find something that will give me the executing directory in a platform-agnostic manner, that is, it searches the correct directory in both a unit test and a web application.</p> <p>I've tried:</p> <pre><code>Assembly.GetExecutingAssembly().Location //Works as a test but not on a server Application.ExecutablePath //Not an executable, so this won't work System.AppDomain.CurrentDomain.BaseDirectory //Almost works in web app, but stops too early in the directory structure Environment.CurrentDirectory //returns system32 directory </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload