Featured post
c# - Reflection methods fail when types are in other assembly -
i'm making little tool analyze code dependencies recursively. found problem: if try member of class signature contains reference dll method fails. example, if have simple class in main.exe
public class mainclass { public mainclass () { foo(); } public containedclass getpublicclass () { return new containedclass (); } }
and containedclass
defined in other file refers.dll, when try following code throw filenotfoundexception
in met3.returntype()
method cause .net not find refers.dll.
assembly assem = assembly.loadfile(@"d:\dir\main.exe"); type typ = assem.gettype ("multiplereference.mainclass"); methodinfo met3 = typ.getmethod ("getpublicclass"); met3.returntype.tostring ();
is there way indicate search dll?
thanks in advance , sorry english.
use loadfrom instead of loadfile because resolve , load dependent assemblies. quoting documentation:
use loadfile method load , examine assemblies have same identity, located in different paths. loadfile not load files loadfrom context, , not resolve dependencies using load path, loadfrom method does. loadfile useful in limited scenario because loadfrom cannot used load assemblies have same identities different paths; load first such assembly.
- Get link
- X
- Other Apps
Comments
Post a Comment