的Python .NET"找不到装配"错误找不到、错误、Python、NET

2023-09-03 07:27:40 作者:橘味果酱

我使用CPython的,我有一个C#DLL。我试图使用Python对于.NET,让他们谈谈。我不能使用IronPython的,因为我需要将这一到现有的CPython系统。

I'm using CPython and I have a C# dll. I'm trying to use Python for .NET to make them talk. I can't use IronPython because I need to integrate this into an existing CPython system.

我完全陌生的Python .NET和我其实很少有经验的Python和C#的经验。所以,请原谅我,如果我的问题似乎很基本的。

I'm completely new to Python for .NET, and I actually have very little experience with Python and no experience with C#. So please forgive me if my question seems very basic.

我使用Python 2.7.3,和我下载 pythonnet-2.0-α-2- clr2.0_131_py27_UCS2并解压缩到一个名为pyfornet_test文件夹,其中还包含了DLL,我试图用(称为DotNet4Class.dll)

I'm using Python 2.7.3, and I downloaded pythonnet-2.0-alpha2-clr2.0_131_py27_UCS2 and unzipped it into a folder named pyfornet_test, which also contains the dll I'm trying to use (called DotNet4Class.dll)

然后我跑这样的:

import sys

import os

import clr

sys.path.append(r"C:\pyfornet_test")

clr.AddReference("DotNet4Class.dll")

这给了我这个错误:

Which gives me this error:

System.IO.FileNotFoundException: Unable to find assembly 'DotNet4Class.dll'.
   at Python.Runtime.CLRModule.AddReference(String name) in C:\Users\Barton\Documents\Visual Studio 2008\Projects\PyShar
p\trunk\pythonnet\src\runtime\moduleobject.cs:line 375

任何意见将是多少AP preciated。谢谢!

Any advice would be much appreciated. Thank you!

推荐答案

DotNet4Class.dll 建立在.NET 4?我认为这样的基础上DLL的命名。

Is DotNet4Class.dll built against .NET 4? I assume so based on the naming of the dll.

请注意这里的问题:http://sourceforge.net/tracker/?func=detail&aid=3293169&group_id=162464&atid=823891

当组件构建在.NET 4.0 clr.AddReference失败 - ID:3293169

clr.AddReference fails when assembly is built with .NET 4.0 - ID: 3293169

我读了解决方案,但本质上,你需要重建和重新编译在.NET 4蟒蛇的.NET项目。

I'd read the solution, but essentially, you need to rebuild and recompile the python for .NET project under .NET 4.

我还会提到,像这样的项目,并没有积极开发和使用的很多人认为,一般有细微的的特质的,使该平台必须解决的问题,如知识本。这听起来像你试图在破解这一解决方案,而无需了解太多关于Python或.NET它始终将是充满了问题。

I'll also mention that projects like this, that aren't actively developed and used by lots of people, generally have subtle idiosyncrasies that make knowledge of the platform essential to work around problems such as this. It sounds like you're trying to hack this solution in without understanding much about python or .NET which is always going to be fraught with problems.