Loading and unloading AppDomains and Assemblies

Posted on 2007-10-12
Last Modified: 2013-11-07
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!
Question by:Paracom_Inc
    LVL 14

    Accepted Solution

    This looks like a pretty good description and guide, with some sample code available.,1759,1790388,00.asp


    Author Comment

    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.
    LVL 14

    Expert Comment

    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>>

    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. :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    Suggested Solutions

    Title # Comments Views Activity
    C# - SOLID Question 6 35
    What are the big features of MVC5? 4 30
    Aspnet xml 2 27
    Xamarin 10 18
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now