Calling Into Assemblies

When calling into the entrypoints of an assembly, it is recommended that you use the same activation context that was active when searching for the assembly. At minimum, ensure that the component loading the assembly does not accidentally get the activation context your application is using. Leaking activation context across DLL boundaries can lead to unexpected dependencies. This is not a problem if your application compiles ISOLATION_AWARE_ENABLED because in that case no activation context is active by default. If you do not compile with ISOLATION_AWARE_ENABLED defined, you should activate the NULL activation context or the same activation context that was used to load the assembly.

The following example ensures that the hosted DLL runs in a context that it recognizes:

ULONG_PTR ulpCookie;
ActivateActCtx(hTheActCtxForMyDll, &ulpCookie);
	DeactivateActCtx(0, ulpCookie);