c# - Implementation of Interface Invalid -
i've been trying make module, command-line-like application. each module can hold multiple commands. example, "module a" can have commands "exit" , "echo". i'm using following code load , initialize modules...
foreach (string filename in directory.getfiles(path.combine(appdomain.currentdomain.basedirectory, @"modules"), "*.dll")) { assembly asm = assembly.loadfrom(filename); foreach (type asmtype in asm.gettypes()) { if (asmtype.getinterface("icommandmodule") != null) { object commandobject = activator.createinstance(asmtype); icommandmodule commandmodule; if (commandobject icommandmodule) { commandmodule = (icommandmodule)commandobject; } else { throw new exception("commandobject not valid icommandmodule."); } ...
i know fact module loading (core.dll) in compliance icommandmodule interface. when make sure if (commandobject icommandmodule)
throws exception. when removed if statement alltogether, told me unable cast commandobject
icommandmodule
.
your application may finding assembly icommandmodule in 2 different directories. assemblies may same, because in different directories type system sees them different.
Comments
Post a Comment