Question

Can multiple AppDomains be used to insulate memory in unmanaged dll too? Just to clarify, if I have an unmanaged dll using some internal static global variable, what will happen if I load that unmanaged dll in different appdomains? Can I safely suppose the dll will be loaded in different address spaces so they have all its own copy of the shared data?

Was it helpful?

Solution

No, that's not possible. AppDomains are purely managed concept. Unmanaged DLL state is process-wide and there can be only one copy of the DLL loaded. A possible hack is to create copies of the DLL file with different names. It however scales very poorly and the pinvoke is nasty, having to write delegates and use LoadLibrary + GetProcAddress to bind them.

The cleaner alternative is to use separate helper processes that loads the DLL. Talk to them with an interop mechanism like WCF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top