c# - Python for .NET: Using same .NET assembly in multiple versions -
my problem: have assembly in 2 versions , want use them @ same time in python project.
the .net libs installed in gac (msil), having same public token:
lib.dll (1.0.0.0) lib.dll (2.0.0.0)
in python want that:
import clr clr.addreference("lib, version=1.0.0.0, ...") lib import class myclass1 = class() myclass1.operation() *magic* clr.addreference("lib, version=2.0.0.0, ...") lib import class myclass2 = class() myclass2.operation() myclass2.operationfromversion2() *other stuff* # both objects should accessibly myclass1.operation() myclass2.operationfromversion2()
is there way that? appdomains or bindingredirect?
note: of course myclass1.operationfromversion2() can fail...
well found solution: python .net supports reflection!
instead of
clr.addreference("lib, version=1.0.0.0, ...")
you have use
assembly1 = clr.addreference("lib, version=1.0.0.0, ...")
with assembly can use reflection stuff in c#. in example have use following code (same version 2):
from system import type type1 = assembly1.gettype(...) constructor1 = type1.getconstructor(type.emptytypes) myclass1 = constructor1.invoke([])
Comments
Post a Comment