On Wednesday, 4 March 2015 at 16:08:00 UTC, Steven Schveighoffer
wrote:
curiously not listed? That doesn't make any sense. If there is
not a cycle in the listed modules, where at least 2 modules
have a static ctor or static dtor, then there is a bug in the
cycle detection code.
Source code is available here: https://github.com/rumbu13/sharp
The runtime error chain was "system.globalization ->
internals.locale ->
system.runtime.interopservices -> system.io ->
system.globalization
Three of these modules import "internals.resources" containing a
static constructor. The static dtor is in
system.runtime.interopservices.
Clearly, the above is not an issue, but at the moment, the code
treats having a ctor and having a dtor as the same thing. How
to fix it? I'm not exactly sure, you need to have the modules
sorted according to ctor and also according to dtor. The
runtime is supposed to run dtors in reverse order from ctor
calls, and I think we should not break that. But there is
definitely room to allow for reordering when ctors are not
affected.
I'll have to think about it some more.
-Steve
Why bother? I'll leave this to the programmer, he can take full
responsibility to not mess up module ctors/dtors. I remember the
old Delphi days where this was assumed from the start:
initialization and finalization order of execution (equivalent of
static ctor/dtor) were not guaranteed. It was better to obtain an
AccessViolation or a StackOverflow and correct the circular
reference, instead of a NEVER running executable.