.net - LoaderLock error on program termination -


I have integrated a .NET Nlog logging component in our applications recently purely unmanaged code (C + + And VB 6 components compiled in Visual Studio 6) We have a bunch of C ++ apps that talk to NLog via the COM interface.

Doing everything works fine, but I think the following message pops up that (as in the Output window that C ++ component debugging VS a prompt 6; IDE that program termination During NLog debugging through VLS 2005):

Loader lock was detected Message: Taking the managed execution inside the OS loader lock. Do not try to run the managed code within the DelMen or Image Initialization function, by doing so, the app can be hung.

DllMain as follows:

  outer "C" Bull Vineepi Delmen (Histain H. instance, Deedward Dwarjhn, Elpivioaidi / * LP reserve / /) (if (dwReason == DLL_PROCESS_ATTACH) {_Module.Init (Objektmap, H instance); DisableThreadLibraryCalls (hInstance);} if (dwReason == DLL_PROCESS_DETACH) _Module.Term (); return TRUE; // ok}  

My guess is that _Module.Term (); now includes issuing some .NET references (I'm keeping reference to a NLog one of my C ++ class To the object Destroy each time Instilt to avoid and escape release) who pop up this warning.

My question: What is not safe to ignore it? If so, so what's the best solution? (the best I can think of is to instantiate the context of the Nlog object and every time I wanted to write in the log file ... solutions is not the most elegant)

This message is definitely not safe. If you hit this message, then you've almost certainly created a real loader lock policy violation. This is a very serious error, and there may be unpredictable behavior in a program (including deadlock).

The best way to avoid this is to not direct any other Net objects / functions directly or indirectly into the DLL key. For your case, it is best to use a different cash policy. Generally create a referee math object to capture the net reference. In this way the object will be released before that DllMain is called to unload (unless DLL can not be loaded until all of your objects are destroyed).


Comments