Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:21:38+00:00 2026-06-04T15:21:38+00:00

Possible Duplicate: .NET NUnit test – Assembly.GetEntryAssembly() is null I’m writing a logging library.

  • 0

Possible Duplicate:
.NET NUnit test – Assembly.GetEntryAssembly() is null

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”.

I’m using this code to construct the path:

   private static string loggingDataPath = 
      Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
      Path.DirectorySeparatorChar + 
      Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase) +
      Path.DirectorySeparatorChar;

This works exactly as expected, with one problem. I can’t unit test the library!

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.

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.

TIA!

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:21:40+00:00Added an answer on June 4, 2026 at 3:21 pm

    Ignoring the sage advice of previous answers and addressing only my question, here is how I fixed the problem:

       public static string LoggingDataPath { 
          get { 
             return loggingDataPath.Length > 0 ? loggingDataPath : 
             Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + 
             Path.DirectorySeparatorChar + 
             Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase) + 
             Path.DirectorySeparatorChar; 
          } 
    
          set { loggingDataPath = value; } 
       } 
    

    This solution avoids initializing ‘loggingDataPath’ on the first access to the static class, thus avoiding the call to ‘Assembly.GetEntryAssembly().CodeBase’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: .NET file system wrapper library I would like to write a test
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: CSV File Imports in .Net In .net, is there a standard library
Possible Duplicate: .Net Process.Start default directory? I have a C# application, mono to be
Possible Duplicate: Windows API and .net languages I want to call native Windows API
Possible Duplicate: ASP.Net: DropDownList's SelectedIndexChanged event not firing I created a new ASP.NET default
Possible Duplicate: ASP.NET authentication login and logout with browser back button I want to
Possible Duplicate: Merging .net managed dlls I create a test project in which I
Possible Duplicate: Why does .NET use banker's rounding as default? Here is a sample
Possible Duplicate: Duplicate keys in .NET dictionaries? I want to use a kind of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.