Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:18:28+00:00 2026-06-02T23:18:28+00:00

if i use Assembly assembly = Assembly.LoadFrom(file); and later try to use the file

  • 0

if i use

Assembly assembly = Assembly.LoadFrom(file);

and later try to use the file , i get an exception stating that the file is in use .

i need to load it on to a new appdomain .

all i seem to find is examples of how to create an instance with in the Assembly ,
is there a way to load the entire assembly.

what i need is to :

 (1) load the assembly into a new AppDomain from a file . 
 (2) extract an embedded  resource (xml file) from the Dll .
 (3) extract a type of class which implements an interface (which i know the interface type) .
 (4) unload the entire appdomain in order to free the file .  

2-4 is not a problem

i just can’t seem to find how to load the Assembly into a new AppDomin , only examples of
create instance , which gives me an instace of the class from with in the Dll .

i need the entire thing.

like in this question : another example of Create instance .

Loading DLLs into a separate AppDomain

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:18:29+00:00Added an answer on June 2, 2026 at 11:18 pm

    The most basic multidomain scenario is

    static void Main()
    {
        AppDomain newDomain = AppDomain.CreateDomain("New Domain");
        newDomain.ExecuteAssembly("file.exe");
        AppDomain.Unload(newDomain);
    }
    

    Calling ExecuteAssembly on a seperate domain is convienient but does not offer the ability to interact with the domain itself. It also requires the target assembly to be an executable and forces the caller to a single entry point. To incorporate some flexibility you could also pass a string or args to the .exe.

    I hope this helps.

    Extension: Try something like the following then

    AppDomainSetup setup = new AppDomainSetup();
    setup.AppDomainInitializer = new AppDomainInitializer(ConfigureAppDomain);
    setup.AppDomainInitializerArguments = new string[] { unknownAppPath };
    AppDomain testDomain = AppDomain.CreateDomain("test", AppDomain.CurrentDomain.Evidence, setup);
    AppDomain.Unload(testDomain);
    File.Delete(unknownAppPath);
    

    where the AppDomain can be initilised as follows

    public static void ConfigureAppDomain(string[] args)
    {
        string unknownAppPath = args[0];
        AppDomain.CurrentDomain.DoCallBack(delegate()
        {
            //check that the new assembly is signed with the same public key
            Assembly unknownAsm = AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(unknownAppPath));
    
            //get the new assembly public key
            byte[] unknownKeyBytes = unknownAsm.GetName().GetPublicKey();
            string unknownKeyStr = BitConverter.ToString(unknownKeyBytes);
    
            //get the current public key
            Assembly asm = Assembly.GetExecutingAssembly();
            AssemblyName aname = asm.GetName();
            byte[] pubKey = aname.GetPublicKey();
            string hexKeyStr = BitConverter.ToString(pubKey);
            if (hexKeyStr == unknownKeyStr)
            {
                //keys match so execute a method
                Type classType = unknownAsm.GetType("namespace.classname");
                classType.InvokeMember("MethodNameToInvoke", BindingFlags.InvokeMethod, null, null, null);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

System.Reflection.Assembly.Load(System.IO.File.ReadAllBytes(path)) So this is a work around to not being able to use T4
I'm trying to use Assembly.Load() to load an assembly that is in the GAC.
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
I use a WsdlImporter and ServiceContractGenerator to set up CodeDomProvider to get an assembly
We all know that the assembly can be queried for attributes using the GetCustomAttributes
I'm trying to use Assembly.Load(Byte[]) in a Silverlight 4 app and i'm getting MethodAccessException.
It's my impression that Assembly.LoadFrom uses the ApplicationBase and PrivateBinPath. It also my impression
It's my impression that Assembly.LoadFrom uses the ApplicationBase and PrivateBinPath. It also my impression
I'm attempting to use Assembly.GetType(MyCompany.Class1.Class2) to dynamically get a type from a string. Assembly.GetType(MyCompany.Class1);
Let's say that I do ilmerge on assembly1 and assembly2. Can I use Assembly.GetExecutingAssembly.GetTypes()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.