Link to home
Start Free TrialLog in
Avatar of Paracom_Inc
Paracom_Inc

asked on

Loading and unloading AppDomains and Assemblies

Is there a way to load an assembly into an AppDomain other than the current AppDomain using the file path to the assembly? I need to be able to load and unload assemblies, so I assumed that the best way to do this is with AppDomains, but I haven't been able to make it work. I need to be able to load an assembly into a newly created AppDomain, get a proxy to a type in the assembly, call methods on the proxy, then unload the AppDomain. And I need to be able to do this all without loading the assembly into the local AppDomain. There must be a way to do this, but I haven't figured it out yet. Does somebody know how to do this? Thanks!
ASKER CERTIFIED SOLUTION
Avatar of steveberzins
steveberzins

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paracom_Inc
Paracom_Inc

ASKER

The article doesn't specifically answer my question, but it is a great article on the related topic of loading and unloading code. Thanks. By the way, it appears that the simple answer to my question is no. Only Assembly.LoadFile() appears to take a file path as a parameter. The AppDomain methods that load an assembly do so by assembly FullName.
sorry, missed that part of the question...

if you look at the overload of AppDomain.CreateDomain that takes a parameter of type AppDomainSetup, you can use an AppDomainSetup to not only specify the path, but specify a separate config file, whether and where to shadow copy...

AppDomainSetup ads = new AppDomainSetup();

ads.ApplicationBase = <<path to assembly>> //directory ending in \, each assembly needs to be in it's own directory as far as I know.
ads.ConfigurationFile = <<nameofconfigfile>>
ads.CachePath = <<path you want to use for shadow copies>>
ads.ShadowCopyFiles="true"

then a call like this, rather than than using the overload that uses only name.

AppDomain ad = AppDomain.CreateDomain(<<domainname>>, AppDomain.CurrentDomain.Evidence, ads);

next time don't give a bad grade if you didn't get your answer, or all of what you were looking for, clarify your needs, give a guy a chance, and we'll get you the answer worth an 'A', and we all win. :)