Note that there are some explanatory texts on larger screens.

plurals
  1. POAssembly.GetEntryAssembly().CodeBase precludes unit testing
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/4337201/net-nunit-test-assembly-getentryassembly-is-null">.NET NUnit test - Assembly.GetEntryAssembly() is null</a> </p> </blockquote> <p>I'm writing a logging library. I want the library, by default, to write to a directory in the common application data folder named for the application. For example, if the application is called "MyApplication.exe", I want the data saved in "C:\ProgramData\MyApplication".</p> <p>I'm using this code to construct the path:</p> <pre><code> private static string loggingDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase) + Path.DirectorySeparatorChar; </code></pre> <p>This works exactly as expected, with one problem. I can't unit test the library! </p> <p>When I try to run the unit tests they all fail with a System.NullReferenceException. If I replace the "Assembly.GetEntryAssembly().CodeBase" call with a string the unit tests once again function properly.</p> <p>I think I understand why this happens but I have no idea how to work around the problem. I hope someone will be able set me on the path of righteousness.</p> <p>TIA!</p> <p>UPDATE (5-24-12): I am not trying to unit test the contents of "loggingDataPath". The mere presence of the "Assembly.GetEntryAssembly().CodeBase" call causes ALL unit tests to fail with the above exception. Note that "loggingDataPath" is static (as it must be as this is a static library).</p>
 

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