如何引用针对 IronPython 2.7 中运行时版本 'v2.0.xxx' 构建的程序集?



我正在尝试为针对运行时版本"v2.0.50727"构建的程序集(第三方DLL)创建包装器。但是每当我尝试在 IronPython 代码中引用它时,它总是会导致以下错误

IOError:System.IO.FileLoadException:混合模式程序集是针对运行时版本"v2.0.50727"构建的,如果没有其他配置信息,则无法在 4.0 运行时中加载。

我的包装器只是一个类库,所以没有app.config或app.exe.config。

  1. 我尝试将库的目标框架更改为.NET Framework 2.0,但它不起作用。给了我同样的错误。
  2. 甚至尝试了 http://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/,但它在 python 中不起作用,并给了我以下异常

    运行时已绑定到旧版激活策略使用。

Python代码非常简单

import clr
import sys
sys.path.append(r"directoryPath")
clr.AddReference(r"Test.dll")
from Test import *
testObj = testClass()
raw_input("Press enter key to continue..")

包装类库具有以下内容

namespace Test
{
public class testClass()
{
public testClass()
{
thirdPartyDLLClass tClass = new thirdPartyDLLClass();
}
}
}

我只想编译和运行IronPython程序,没有例外。我任何人都可以建议任何我没有尝试过的新东西,那么它会很有帮助。我对python很陌生,但我在C#方面已经足够好了。

提前谢谢。

通过在我的 PythonApp.exe.config 文件中进行更改来解决它。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true"> 
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.x.x"/></startup>
</configuration>

如果没有配置文件,只需创建一个与 python 应用名称同名的 .config 文件。

最新更新