I am planning to expose a .NET component with a COM interface, and I would like all the instances of the .NET class to share a single Application Domain.
What would be the best way of achieving that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If it is possible it will not be easy.
While creating an instance of a type in a known
AppDomainis easy (eg.Activator.CreateInstanceoverload that takes anAppDomainreference), the problem will be getting the reference to the targetAppDomain.Creating the
AppDomainand sharing that reference within the currentAppDomainis easy: astaticfield or property.Sharing that reference to other AppDomains created by third party code is a problem. I seem to recall parts of the BCL do share statics across domains (essentially they have a single instance per process rather than per
AppDomain, but this mechanism isn’t generally accessible to other assemblies.It is probably better to understand why you want to be able to do this: there is probably a better solution to your underlying problem: why do you want all instances in a single
AppDomain?