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

  • Home
  • SEARCH
  • 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 7441069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:57:08+00:00 2026-05-29T10:57:08+00:00

This question is more about C# than it is about log4net (I think). I

  • 0

This question is more about C# than it is about log4net (I think).

I created a custom appender and let it read a static field that was set previously by the program.

To my astonishment the static field was reinitialized and the set value dit not make it to the appender.

I fired up debugview and saw that the static constructor is called twice (!). This should not be possible in the same appdomain right?
Only debugview brought this to light since VS didn’t hit a second time on the breakpoint.

Note that this is not a question about avoiding the use of static variable with log4net. I’m interested in what kind of magic log4net uses to accomplish this?

Edit #1

Hello Jon, Big fan.

I isolated it further as requested. First I started blank and worked towards the target situation that exposes the error. Since I almost matched the target character by character and still didn’t repro I went the other way round.

Starting from the error situation I stripped out everything that I deemed not essential till it started … working as expected.

It seems there is some weird thing hoing on when the runtime tries to resolved the log4net assembly (as observed in debug mode)

This is what I see with debugview:

[7756] General: WARN – Failed to parse module’s ‘log4net’ version . Exception: System.NullReferenceException: Object reference not set to an instance of an object.
[7756] at DebuggerShared.Services.EventArgs.ModuleLoadedInDebuggerEventArgs..ctor(String modulePath, String moduleLoadMessage, Boolean isUserCode, String name, String version)
[7756] General: WARN – Failed to parse module’s ‘FollowUp.Common’ version . Exception: System.NullReferenceException: Object reference not set to an instance of an object.
[7756] at DebuggerShared.Services.EventArgs.ModuleLoadedInDebuggerEventArgs..ctor(String modulePath, String moduleLoadMessage, Boolean isUserCode, String name, String version)

And VS shows no value for the path in the debug-module screen. Now how did I managed to come to that situation? Weird that it managed to load an assembly but can’t tell anymore from where 🙂

Here is the isolated situation to the point that if I modify it further it starts working as expected.

https://www.sugarsync.com/pf/D6486369_1701716_00940

I’m still interested in the technical details but after removing the reference to log4net and adding it again it all started to work again.
I’m happy that it works but it nags me that I don’t have a thorough explanation

Also, the static constructor iscalled twice now which makes sense since the type is initializes again when log4net gets its hands on it.

I think it isn’t worthwhile to spent more time on this cause I think the solution was in a weird state and to understand all this has marginal value.
Still, if you can think of something to explain this I’d be glad to here.

Edit #2

It turned out that some assemblies were indeed loaded twice including the one with the static constructor. I’ll investigate later how this is possible but I have a workaround by disabling and enabling Costura. Costura is a msbuild task that merges all the assemblies into one.
I’m not saying that Costura is the root cause. It could easily be that the csproj/sln files were in strange state.

Thinking on how to diagnose this problem faster in the future I fired up sysinternals ProcessExplorer.
Now I expected to see the assemblies being loaded only once but I found saw that they were loaded twice. Seems this is a bug in the runtime thats fixed only in .NET 4

http://forum.sysinternals.com/why-some-net-assemblies-are-duplicated-in-memory_topic15279.html
https://connect.microsoft.com/VisualStudio/feedback/details/467560/clr-maps-assemblies-into-the-virtual-address-space-twice

Edit #3
Costura made the assemblies load twice. The issue was fixed on the same day by the project owner 🙂 http://code.google.com/p/costura/issues/detail?id=17&thanks=17&ts=1328826304

We need a Costura tag but I don’t have the necessary 1500 reputation points. Please create it if you have the rights. Thanks.

Kind Regards, Tom

  • 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-05-29T10:57:09+00:00Added an answer on May 29, 2026 at 10:57 am

    It looks like you managed to load two separate instances of log4net into the same AppDomain.

    One project references:

    <Reference Include="log4net">
      <HintPath>..\packages\log4net.1.2.11\lib\net35-full\log4net.dll</HintPath>
    </Reference>
    

    The other:

    <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\ExternalReferences\log4net.dll</HintPath>
    </Reference>
    

    One of them is strongly named, the other isn’t, this resulted in .net giving them different identities. And the hint path differs too. Also one seems to be 1.2.10, the other 1.2.11.

    try calling AppDomain.GetAssemblies() and check if log4net occurs twice.

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

Sidebar

Related Questions

This question is more about curiosity than utility. If I'm writing a function that's
EDIT: This question is more about language engineering than C++ itself. I used C++
More than about LINQ to [insert your favorite provider here], this question is about
So I'm trying to learn more about lambda expressions. I read this question on
Hullo to all! This question is more about a shortcut than anything: Is there
Some of this question is related to JPA, but it's more about approaches than
This is a question more about best practices/design patterns than regexps. In short I
This is a question more about how to build a c++ application than it
This isn't really a programming question but more about programming and testing tools. Is
I got this in an interview question -- the question was more about what

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.