Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Load an assembly dynamically in a new App Domain

Load an assembly dynamically in a new App Domain

Scheduled Pinned Locked Moved C#
questiondata-structures
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaurGurpreet
    wrote on last edited by
    #1

    How do I load an Assembly dynamically in a NEW appdomain? The assembly is in bytes[] array. Gurpreet

    C L 2 Replies Last reply
    0
    • K KaurGurpreet

      How do I load an Assembly dynamically in a NEW appdomain? The assembly is in bytes[] array. Gurpreet

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      You should look for articles that deals with reflection and plugins. YOu should be able to get the code you need from there. I have a little plugin system on my page too (oldow it does not load an assembly into a new appdomain): http://cwizo.slogamedev.net/index.php?i=showcase&s=programs Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      K 1 Reply Last reply
      0
      • K KaurGurpreet

        How do I load an Assembly dynamically in a NEW appdomain? The assembly is in bytes[] array. Gurpreet

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        KaurGurpreet wrote:

        How do I load an Assembly dynamically in a NEW appdomain?

        Just you would normally, but you need to call it from within that AppDomain. ;)

        xacc.ide-0.1.2.12
        Now with more features and one less bug!

        1 Reply Last reply
        0
        • C CWIZO

          You should look for articles that deals with reflection and plugins. YOu should be able to get the code you need from there. I have a little plugin system on my page too (oldow it does not load an assembly into a new appdomain): http://cwizo.slogamedev.net/index.php?i=showcase&s=programs Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

          K Offline
          K Offline
          KaurGurpreet
          wrote on last edited by
          #4

          _________________________________________________________ The Assembly that I need to load: _________________________________________________________ namespace WindowsApplication4 { public class TestDll : MarshalByRefObject,interfaces.Test { public string HelloWorld() { return "Hello World"; } } } _________________________________________________________ interfaces.Test is in a seprate dll. code is as below: _________________________________________________________ namespace interfaces { public interface Test { string HelloWorld(); } } _________________________________________________________ The code that I am using to load: _________________________________________________________ AppDomain currentDomain = AppDomain.CreateDomain("mydomain1"); currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver); domain.CreateInstance("TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "WindowsApplication4.TestDll"); static Assembly MyResolver(object sender, ResolveEventArgs args) { Assembly assembly; AppDomain domain = (AppDomain)sender; // Actually the assembly in bytes will come from database so temporarily loading it as below: byte[] rawAssembly = loadFile("d:\\TestAssembly.dll"); assembly = domain.Load(rawAssembly); return assembly; } I DO NOT FACE ANY PROBLEM IN LOADING THE ASSEMBLY WHEN IT IS NOT IMPLEMENTING THE INTERFACE. IT WORKS FINE IN THAT CASE. Gurpreet -- modified at 3:12 Wednesday 15th February, 2006

          C 1 Reply Last reply
          0
          • K KaurGurpreet

            _________________________________________________________ The Assembly that I need to load: _________________________________________________________ namespace WindowsApplication4 { public class TestDll : MarshalByRefObject,interfaces.Test { public string HelloWorld() { return "Hello World"; } } } _________________________________________________________ interfaces.Test is in a seprate dll. code is as below: _________________________________________________________ namespace interfaces { public interface Test { string HelloWorld(); } } _________________________________________________________ The code that I am using to load: _________________________________________________________ AppDomain currentDomain = AppDomain.CreateDomain("mydomain1"); currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver); domain.CreateInstance("TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "WindowsApplication4.TestDll"); static Assembly MyResolver(object sender, ResolveEventArgs args) { Assembly assembly; AppDomain domain = (AppDomain)sender; // Actually the assembly in bytes will come from database so temporarily loading it as below: byte[] rawAssembly = loadFile("d:\\TestAssembly.dll"); assembly = domain.Load(rawAssembly); return assembly; } I DO NOT FACE ANY PROBLEM IN LOADING THE ASSEMBLY WHEN IT IS NOT IMPLEMENTING THE INTERFACE. IT WORKS FINE IN THAT CASE. Gurpreet -- modified at 3:12 Wednesday 15th February, 2006

            C Offline
            C Offline
            CWIZO
            wrote on last edited by
            #5

            I am guessing but I think that you should add refrence to the Interface dll in your TestDLL but you should really post some error or something. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

            K 1 Reply Last reply
            0
            • C CWIZO

              I am guessing but I think that you should add refrence to the Interface dll in your TestDLL but you should really post some error or something. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

              K Offline
              K Offline
              KaurGurpreet
              wrote on last edited by
              #6

              I get the following error: {"Could not load file or assembly 'TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"} reference of interface.dll is added in Testdll. Testdll can not be compiled without the reference :) Gurpreet

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups