reflection - C# Load Assembly w/ Common References -


i've run slight issue - i'm writing program loads dlls, each of contain class inherits class existing in library referenced both loaded dll , "host" program loading dll. issue here that, when try load , cast superclass:

var assembly = assembly.loadfrom(dllpath); var type = assembly.gettypes().firstordefault(x => x.issubclassof(typeof (mysuperclass))); ... 

although both referencing class containing mysuperclass, since dll referencing built class library (a separate file class library file loading program referencing) issubclassof never returns true, because considers 2 classes different come 2 different assemblies.

furthermore, if try casting created instance of loaded class superclass type, can't since they're not same (different assemblies).

so, question is: how handle loading assemblies reference common code, c# recognizes you're loading class inherits common superclass?

you must use same assembly files (even if identical) if want programs work using common code. here's how solved issue:

the program loading dll subdirectory of own.

folder structure:

myapp folder -->      myprogram.exe      commondependency.dll      submodules ->          mysubmodule.dll 

to mysubmodule use commondependency.dll within next folder up, it's quite simple. configure visual studio not copy these dll dependencies build folder. next, create app.config in visual studio , add following:

<configuration>   <runtime>     <assemblybinding>       <probing privatepath="../"/>     </assemblybinding>   </runtime> </configuration> 

this tell system search assemblies in parent folder ../ - if want have multiple folders, perhaps separate dependency folder (relative location of .dll) can use ; delimiter - ../;../bin/; - program search these locations dependencies.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -