Friday 15 May 2015

c# - Assembly conflict when using Type.IsAssignableFrom(Type) -



c# - Assembly conflict when using Type.IsAssignableFrom(Type) -

i loading dll dynamically assembly. problem when seek utilize system.reflection type loaded assembly, want utilize create instance of type. type want happens interface.

this based on code have used in past, new project, fails. problem seems types beingness compared 2 different assemblies.

here code:

imyinterface _classinstance; string path = path.combine(application.startuppath, "mydynamic.dll"); if (file.exists(path)) { byte[] ba = file.readallbytes(path); if (ba.length > 0) { assembly dll = assembly.load(ba); if (dll != null) { foreach (type t in dll.gettypes()) { if (typeof(imyinterface).isassignablefrom(t)) _classinstance = (imyinterface)activator.createinstance(t); } } } }

using advice this question, able determine typeof(imyinterface).module.fullyqualifiedname returns executing application (the exe debugging). that, of course, not match see t.module.fullyqualifiedname, dll.

i resolve without injecting go-between assembly nil provide type, if possible.

satisfaction curious...

the reply came downwards making little concession in project design. instead of linking interface class (code page) each project, , allowing each project own stand-alone entity, had reference class in main exe project. , instead of incorporating own links imyinterface , individual dlls create assembly reference exe project.

this resolved incompatibility issue between exe's type , loaded dll's type.

i "small concession" because design have dll in exe's working directory loaded @ runtime, project reference changes nil philosophically.

c# reflection .net-assembly

No comments:

Post a Comment