Sharing NGEN image in Multi-Domain Host

To reuse the same NGEN image of an assembly for every domain in a multi-domain environment, the assembly has to be loaded as domain neutral.

To enable domain neutral assemblies, the host must enable domain sharing when it starts CLR.

This is all discussed in my previous blog Domain Neutral Assemblies. Specifically,

<quote>

There are two ways for a host to specify this hint. One way is through hosting API CorBindToRuntimeEx. Another way is decorating your Main method with LoaderOptimizationAttribute.

</quote>

If the host did not enable domain sharing when it started CLR, NGEN image will be used in the first appdomain. The other appdomains will JIT compile the assemblies.