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 48783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:20:03+00:00 2026-05-10T16:20:03+00:00

Ok, so I just ran into the following problem that raised an eyebrow. For

  • 0

Ok, so I just ran into the following problem that raised an eyebrow.

For various reasons I have a testing setup where Testing classes in a TestingAssembly.dll depend on the TestingBase class in a BaseTestingAssembly.dll. One of the things the TestBase does in the meantime is look for a certain embedded resource in its own and the calling assembly

So my BaseTestingAssembly contained the following lines…

public class TestBase {       private static Assembly _assembly;   private static Assembly _calling_assembly;    static TestBase() {     _assembly = Assembly.GetExecutingAssembly();     _calling_assembly = Assembly.GetCallingAssembly();   } } 

Static since I figured, these assemblies would be the same over the application’s lifetime so why bother recalculating them on every single test.

When running this however I noticed that both _assembly and _calling_assembly were being set to BaseTestingAssembly rather than BaseTestingAssembly and TestingAssembly respectively.

Setting the variables to non-static and having them initialized in a regular constructor fixed this but I am confused why this happened to begin this. I thought static constructors run the first time a static member gets referenced. This could only have been from my TestingAssembly which should then have been the caller. Does anyone know what might have happened?

  • 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. 2026-05-10T16:20:03+00:00Added an answer on May 10, 2026 at 4:20 pm

    The static constructor is called by the runtime and not directly by user code. You can see this by setting a breakpoint in the constructor and then running in the debugger. The function immediately above it in the call chain is native code.

    Edit: There are a lot of ways in which static initializers run in a different environment than other user code. Some other ways are

    1. They’re implicitly protected against race conditions resulting from multithreading
    2. You can’t catch exceptions from outside the initializer

    In general, it’s probably best not to use them for anything too sophisticated. You can implement single-init with the following pattern:

    private static Assembly _assembly; private static Assembly Assembly {   get {     if (_assembly == null) _assembly = Assembly.GetExecutingAssembly();     return _assembly;   } }  private static Assembly _calling_assembly; private static Assembly CallingAssembly {   get {     if (_calling_assembly == null) _calling_assembly = Assembly.GetCallingAssembly();     return _calling_assembly;   } } 

    Add locking if you expect multithreaded access.

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

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer 1) If the Map can be immutable: Collections.emptyMap() // or,… May 11, 2026 at 8:57 am
  • added an answer The options are slightly different. Option 1 allows you to… May 11, 2026 at 8:57 am
  • added an answer The error code and the description of the error states… May 11, 2026 at 8:57 am

Related Questions

Ok, so I just ran into the following problem that raised an eyebrow. For
Ok so I just did something boneheaded. I'm setting up a subversion server for
Ugh ok I'm terrible at explaining things, so I'll just give you the quotes
Ok so I thought it was fixed, but I'm getting totally inconsistent results. I
Ok so I've ordered Applying Domain-Driven Design and Patterns: Using .Net , but while
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
Ok so I have an abstract base class called Product, a KitItem class that
Ok so I've spent a couple hours trying to resolve this issue and have
Ok so I have this regex that I created and it works fine in
Ok so i want to do a prepared insert such as: prepare(INSERT INTO `analyzeditemsdetails`

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.