0

When creating an Application Domain, is it possible to have a set of previously constructed objects that you want to be treated as belonging to that application domain rather than the application domain in which they were originally constructed?

My goal is to adjust some pre-existing code to better isolate memory tests via application domains. However, the point at which inserting usage of application domains that would require the least amount of re-writing of the existing code (when a given test scenario is about to be run so that its memory usage may be monitored) already happens to have some of the data used in the test defined in a test case object.

If I could shift the test case object over to a new application domain, then this would resolve my problem, but I could not locate a way to do so. Making a deep copy of the test case object within a new application domain was another scenario I considered, but there are certain issues that may crop up if some of the assemblies being used in the test case are present in two application domains at the same time (which they technically are if I have an instance of the test case in both domains, even if they are only being actually used in the second domain which was split off from the first).

Edit: The trouble with SetData is that, to my knowledge, it makes a copy. I need the object to effectively stop existing within the original application domain as though it were created in the second application domain. As per the possible duplicate link, the AppDomainSetup only allows for passing in strings (and likely does so via making a copy within the new domain, rather than causing the string to be considered as being under a different logical division of memory).

  • 1
    Possible duplicate of [How to pass a variable from one app domain to another](https://stackoverflow.com/questions/1250676/how-to-pass-a-variable-from-one-app-domain-to-another) – John Wu Aug 15 '17 at 18:58
  • Also, take a look at [SetData](https://stackoverflow.com/questions/37286078/how-to-setdata-to-new-appdomain) – John Wu Aug 15 '17 at 18:59
  • Communication between app domains is close to cross-process communication... In most cases code either will not work when some objects moved to other domain or have very subtle bugs (like some things start copied by value)... beware... – Alexei Levenkov Aug 15 '17 at 19:25

0 Answers0