how to load referenced assemblies
-
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?????? -
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??????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 theAppDomain.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 someStream
), 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-----