Pregunta

I have some questions about the order of initialization for the CLR and the CRT for mixed .NET assemblies (i.e. meaning mixed managed/unmanaged C++ assemblies).

So if I have a mixed mode assembly dll file, and it gets loaded via Assembly.Load. I notice that any static native objects won't get initialized or called until some managed code is called first. OK. So I take it that on startup that the CLR code gets initialized first, and CRT initialization gets called last. How is the order for shutdown? Is the CRT shutdown first, and the CLR shutdown last?

So is this how it goes?

start of program lifetime

initilialize CLR
...initilialize CRT
...construct native static instances

... program runs....

...shutdown CLR
...destruct native static instances
shutdown CLR

end of program lifetime

Or is it in some other order?

My question also applies to mixed mode assemblies that are executables (i.e. .exe). It is similar?

start of program lifetime

initilialize CLR
...initilialize CRT
...construct native static instances

... program runs....

...shutdown CLR
...destruct native static instances
shutdown CLR

end of program lifetime
¿Fue útil?

Solución

This is covered in the MSDN Page for Initialization of Mixed Mode Assemblies.

It's actually the opposite of your idea. Native code gets initialized first, then the managed code. You are not allowed to access any managed code inside of DllMain.

The tear down process order isn't explicitly documented on MSDN, and doesn't appear to be documented explicitly in the C++/CLI specifications. I believe this is implementation specific, and covered under the "Undocumented Behavior" section relating to interaction between native and managed libraries of the appendix.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top