How to reference an assembly which is built against version 'v2.0.xxx' of the runtime in IronPython 2.7?

无人久伴 提交于 2019-12-13 03:39:53

问题


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: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

My wrapper is a Class Library only, so there is no app.config or app.exe.config.

  1. I have tried changing my library's Target Framework to .NET Framework 2.0, but it didn't work. Gave me same error.
  2. Even tried http://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/ , but it didn't work in python and gave me following exception

    A runtime has already been bound for legacy activation policy use.

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();
        }
    }
}

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#.

Thanks in advance.


回答1:


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>

If you don't have an config file, then just create a .config file with the same name as your python app name.



来源:https://stackoverflow.com/questions/56630769/how-to-reference-an-assembly-which-is-built-against-version-v2-0-xxx-of-the-ru

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!