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. how to load referenced assemblies

how to load referenced assemblies

Scheduled Pinned Locked Moved C#
questiontutorial
2 Posts 2 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.
  • O Offline
    O Offline
    occcy
    wrote on last edited by
    #1

    hello! for a testproject I have to load an assembly from a path different to the execution path of my application. the assembly I want to load references other assemblies, which are not system assemblies or assemblies referenced by my application. the way I load this assembly is easy and works: Assembly MyAssembly=System.Reflection.Assembly.Load(AssemblyPathandName); when I enumerate the members of a class of this assembly and the member (for example a method) has a returntype which is declared in a referenced (but not yet loaded) assembly, my application crashs. now my question: how can I load the referenced assemblies or how can I change the searchpath of my application, so that the referenced assemblies can be found and loaded automatic??????

    H 1 Reply Last reply
    0
    • O occcy

      hello! for a testproject I have to load an assembly from a path different to the execution path of my application. the assembly I want to load references other assemblies, which are not system assemblies or assemblies referenced by my application. the way I load this assembly is easy and works: Assembly MyAssembly=System.Reflection.Assembly.Load(AssemblyPathandName); when I enumerate the members of a class of this assembly and the member (for example a method) has a returntype which is declared in a referenced (but not yet loaded) assembly, my application crashs. now my question: how can I load the referenced assemblies or how can I change the searchpath of my application, so that the referenced assemblies can be found and loaded automatic??????

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There are a few ways that assemblies are found. First, the CLR will read from <runtime> section of the .config file and see if you've configured any paths for bound assemblies. The application will then use assemblies in the Global Assembly Cache (GAC), starting with native (pre-JIT'd) assemblies first, then the other assemblies (those not pre-JIT'd). Assemblies are then used out of the application directory (the directory where you .exe executable is located), followed by any additional subdirectories configured in the <probing> section of you .config file. See http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhowruntimelocatesassemblies.asp[^] for more detailed information. You can also handle the AppDomain.AssemblyResolve event and specify from where the assembly should be loaded (for example, from a different path, across the Internet/an intranet, or even from some Stream), but it's typically better and easier to maintain to work with the CLR and and let Fusion (the assembly binder) do its job.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      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