Python for .NET: Using same .NET assembly in multiple versions

前端 未结 2 1398
你的背包
你的背包 2021-01-14 12:06

My problem: I have an assembly in 2 versions and want to use them at the same time in my Python project.

The .NET libs are installed in GAC (MSIL), having the same p

2条回答
  •  渐次进展
    2021-01-14 12:37

    Well I found a solution: Python for .NET also supports Reflection!

    Instead of

    clr.AddReference("lib, Version=1.0.0.0, ...")
    

    You have to use

    assembly1 = clr.AddReference("lib, Version=1.0.0.0, ...")
    

    With that assembly you can use all the Reflection stuff like in C#. In my example I have to use following code (same for version 2):

    from System import Type
    type1 = assembly1.GetType(...)
    constructor1 = type1.GetConstructor(Type.EmptyTypes)
    myClass1 = constructor1.Invoke([])
    

提交回复
热议问题