如何在IronPython 2.7中引用针对运行时版本'v2.0.xxx'构建的程序集? [英] How to reference an assembly which is built against version 'v2.0.xxx' of the runtime in IronPython 2.7?
问题描述
我正在尝试为针对运行时版本'v2.0.50727'构建的程序集(thirdPartyDLL)创建包装器.但是,每当我尝试在IronPython代码中引用它时,总是会导致以下错误
I am trying to create wrapper for an assembly (thirdPartyDLL) which was built against version 'v2.0.50727' of the runtime. But whenever I try to reference it in IronPython code, it always results in following error
IOError:System.IO.FileLoadException:混合模式程序集是针对运行时的版本"v2.0.50727"构建的,如果没有其他配置信息,则无法在4.0运行时中加载.
我的包装器仅是一个类库,因此没有app.config或app.exe.config.
My wrapper is a Class Library only, so there is no app.config or app.exe.config.
- 我尝试将库的目标框架更改为.NET Framework 2.0,但没有用.给了我同样的错误.
- 甚至尝试过 http://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/,但是它在python中不起作用,并给了我以下异常
- I have tried changing my library's Target Framework to .NET Framework 2.0, but it didn't work. Gave me same error.
- Even tried http://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/ , but it didn't work in python and gave me following exception
运行时已经绑定了旧版激活策略.
Python代码非常简单
Python code is pretty straight forward
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..")
包装器类库具有以下内容
Wrapper class library has following
namespace Test
{
public class testClass()
{
public testClass()
{
thirdPartyDLLClass tClass = new thirdPartyDLLClass();
}
}
}
我只想无例外地编译和运行IronPython程序.我可以建议任何我没有尝试过的新东西,这将非常有帮助.我是python的新手,但是我在C#中已经足够了.
I just want to compile and run the IronPython program without exceptions. I anyone can suggest anything new that I haven't tried then it would be so helpful. I am very new to python but I am good enough in C#.
谢谢.
推荐答案
通过在我的PythonApp.exe.config文件中进行更改解决了该问题.
Solved it by making changes in my PythonApp.exe.config file.
<?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文件即可.
If you don't have an config file, then just create a .config file with the same name as your python app name.
这篇关于如何在IronPython 2.7中引用针对运行时版本'v2.0.xxx'构建的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!