.net - How Do I Load an Assembly and All of its Dependencies at Runtime in C# for Reflection? -


i'm writing utility myself, partly exercise in learning c# reflection , partly because want resulting tool own use.

what i'm after pointing application @ assembly , choosing given class select properties should included in exported html form fields. form used in asp.net mvc app beginning of view.

as i'm using subsonic objects applications want use, should reasonable , figured that, wanting include things differing output html depending on data type, reflection way done.

what i'm looking for, however, seems elusive. i'm trying take dll/exe that's chosen through openfiledialog starting point , load it:

string filepath = path.getdirectoryname(filename); system.reflection.assembly o = system.reflection.assembly.loadfile(filename); 

that works fine, because subsonic-generated objects full of object types defined in subsonic.dll, etc., dependent objects aren't loaded. enter:

assemblyname[] referencedassemblies = o.getreferencedassemblies(); 

that, too, contains expect to. however, i'm trying figure out how load assemblies digging objects work properly. understand if assemblies in gac or in directory of running executable, load them name, isn't case use case , it's primary use case.

so, boils down how load given assembly , of arbitrary assemblies starting filename , resulting in reflection-browsable tree of types, properties, methods, etc.

i know tools reflector this, can't find syntax getting @ it.

couple of options here:

  1. attach appdomain.assemblyresolve , loadfile based on requested assembly.
  2. spin appdomain directory base , load assemblies in appdomain.

i'd highly recommend pursuing option 2, since cleaner , allow unload assemblies after. also, consider loading assemblies in reflection-only context if need reflect on them (see assembly.reflectiononlyload).


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -