loading assemble into AppDomain

This is a discussion on loading assemble into AppDomain within the C# Programming forums, part of the General Programming Boards category; I used to have this code which loads an assembly: Code: Assembly assembly = Assembly.LoadFrom(assemblyName); It works fine but now ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    loading assemble into AppDomain

    I used to have this code which loads an assembly:

    Code:
    Assembly assembly = Assembly.LoadFrom(assemblyName);
    It works fine but now I need to load it into a separate AppDomain.

    Code:
    AppDomain actionsDomain = AppDomain.CreateDomain("Action");
    Assembly assembly = actionsDomain.Load(assemblyName);
    But I cant get this to work. I've tried the assemblyResolve event, full paths to the assembly and what not. Every time an exception is thrown that the dll or one of its dependencies cant be found.

    Anyone know what to do?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Maybe your current AppDomain has other assemblies "assemblyName" depends upon already loaded? Did you reference any assemblies in your current app domain that aren't automatically loaded on new Appdomain creation?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Got working with AppDomain.DoCallback which executes the code in the new AppDomain and doesnt load the assembly in the main AppDomain


    Code:
    AppDomainSetup setup = new AppDomainSetup();
    setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
    
    AppDomain ad = AppDomain.CreateDomain("test", null, setup);
    
    ad.DoCallBack(LoaderCallback);
                
    AppDomain.Unload(ad);
    
            private static void LoaderCallback()
            {
                Assembly ass = Assembly.Load("DllTest");
    
                object o = ass.CreateInstance("DllTest.Testing");
    
                Type t = o.GetType();
                
                PropertyInfo pi = t.GetProperty("Test");
    
                if (pi != null)
                    Console.WriteLine((string)pi.GetValue(o, null));
            }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to call assemble code
    By leetow2003 in forum C Programming
    Replies: 9
    Last Post: 04-07-2012, 10:26 AM
  2. How to assemble the output of gcc -S ?
    By manasij7479 in forum Tech Board
    Replies: 6
    Last Post: 10-13-2011, 04:52 AM
  3. Dll Loading Twice?
    By pobri19 in forum Windows Programming
    Replies: 2
    Last Post: 11-25-2009, 10:26 AM
  4. how come... (bmp loading)
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 03-21-2006, 08:00 PM
  5. Computers what kind of idiots assemble them (i mean the shops)
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-28-2003, 07:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21