c# - Loading the same Assembly twice but with different version -
i have 1 assembly called asm.dll.
this assembly has version 1.0.0.0 (set within assemblyinfo.cs)
then need do code modifications in assembly (still asm.dll), advance version 2.0.0.0 , build again.
now, have 2 files named asm.dll differ respect code modifications , version number.
how load these 2 files during runtime?
addendum:
right trying following:
var asm1 = assembly.loadfrom("dir1\asm.dll"); var asm2 = assembly.loadfrom("dir2\asm.dll"); var types1 = asm1.gettypes(); var types2 = asm2.gettypes(); type type1 = types1.first<type>(t => t.name.equals("myclassiwanttoinstantiate")); type type2 = types2.first<type>(t => t.name.equals("myclassiwanttoinstantiate")); myobject myobject1 = (myobject1)activator.createinstance(type, new object[] { }); myobject myobject2 = (myobject2)activator.createinstance(type, new object[] { });
but following behavior:
the first call
activator.createinstance(...)
correctly returns requested instancemyobject1
the second call
activator.createinstance(...)
returns againmyobject1
instead ofmyobject2
the code compiles , program runs without exception or observable problems, except not
myobject2
i aware of this answer , think code used, same, bit newer (correct me, if wrong).
in answer, using activator.createinstance both objects - using whatever registered globally. believe types loaded specific assemblies not enough this.
in answer linked, assemblies loaded using assembly.loadfile
rather loadfrom
, , createinstance
called on assembly instance, rather using static activator.createinstance
. have tried this?
var asm1 = assembly.loadfile("dir1\asm.dll"); var asm2 = assembly.loadfile("dir2\asm.dll"); myobject myobject1 = (myobject)asm1.createinstance("myclassiwanttoinstantiate"); myobject myobject2 = (myobject)asm2.createinstance("myclassiwanttoinstantiate");
Comments
Post a Comment