c# - Does ReflectionOnlyLoad initialize or otherwise run any code? -
for project i'm working on have analyze several dozen assemblies.
it important none of code contained within these assemblies being run, therefore looked @ assembly.reflectiononlyload
, the documentation on msdn mentions:
loads assembly reflection-only context, can examined not executed. member overloaded. complete information member, including syntax, usage, , examples, click name in overload list.
now know regular assembly.load
runs either initializers or constructors of objects loads, right in assumption not case reflectiononlyload
, or should looking other ways of achieving want?
reflectiononlyload
indeed forbid code assembly executing. has own issues - notably, it's not cabaple of loading dependencies. can tricky, since reflecting on class deriving type defined in different assembly fail.
as far i'm aware, assembly.load
will not run in assembly default (edit: except module initializers, abused; if you're not concerned "hackers", not problem, since normal c# code can't write module initializers, can added in il, , might present in c++/cli assemblies), until make - example, trying value of static field somewhere - again, doing in reflection context cause exception.
in case, whether use reflectiononlyload
or plain old load
, make sure you're loading assembly separate application domain. lets define different security contexts (no full trust untrusted assemblies) , importantly, unload assembly when you're done it. if don't load in separate application domain, you're not getting rid of assembly until restart whole application.
Comments
Post a Comment