C# / IronPython Interop with shared C# Class Library

后端 未结 2 1480
旧巷少年郎
旧巷少年郎 2021-02-03 14:24

I\'m trying to use IronPython as an intermediary between a C# GUI and some C# libraries, so that it can be scripted post compile time.

I have a Class library DLL that is

2条回答
  •  孤城傲影
    2021-02-03 15:13

    This error indicates that your assembly is getting loaded into multiple CLR loader contexts. Rather than adding the reference using clr.AddReferenceToFile you can either switch to clr.AddReference or you can load the assembly from C#. For the former you need to make sure that the assembly is available somewhere that .NET can normally load it (the GAC or in the application base of the process). For the latter you can just do:

    engine.Runtime.LoadAssembly(typeof(MyClass).Assembly);
    

    from your C# host code. Personally I like this 2nd solution a little bit more because not only does it work it saves your users from needing to do the clr.AddRef call from Python.

提交回复
热议问题