使用mono从C#调用IronPython对象

使用mono从C#调用IronPython对象,c#,mono,ironpython,C#,Mono,Ironpython,我有以下IronPython代码 class Hello: def __init__(self): pass def add(self, x, y): return (x+y) 我需要从C#调用它,我得到了以下代码 using System; using IronPython.Hosting; using IronPython.Runtime; using IronPython; using Microsoft.Scripting.Hosting

我有以下IronPython代码

class Hello:
    def __init__(self):
        pass
    def add(self, x, y):
        return (x+y)
我需要从C#调用它,我得到了以下代码

using System;
using IronPython.Hosting;
using IronPython.Runtime;
using IronPython;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;

class Hello {
    public static void Main()
    {
        ScriptEngine engine = Python.CreateEngine();
        ScriptSource script = engine.CreateScriptFromSourceFile("myPythonScript.py");
        ScriptScope scope = engine.CreateScope();

        script.Execute(scope);
    }
}
复制IronPython.dll后,我运行以下命令。(我试着跑gacutil,但我得到了一些

dmcs/r:IronPython.dll callipy.cs 但我得到一些错误信息如下

Could not load file or assembly 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Missing method .ctor in assembly /Users/smcho/Desktop/cs/namespace/IronPython.dll, type System.Runtime.CompilerServices.ExtensionAttribute Can't find custom attr constructor image: /Users/smcho/Desktop/cs/namespace/IronPython.dll mtoken: 0x0a000080 Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. ... 无法加载文件或程序集“Microsoft.Scripting.ExtensionAttribute,版本=2.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 assembly/Users/smcho/Desktop/cs/namespace/IronPython.dll中缺少方法.ctor,类型为System.Runtime.CompilerServices.ExtensionAttribute 找不到自定义属性构造函数映像:/Users/smcho/Desktop/cs/namespace/IronPython.dll mtoken:0x0a000080 无法加载文件或程序集“Microsoft.Scripting.Core,版本=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 无法加载文件或程序集“Microsoft.Scripting.Core,版本=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 无法加载文件或程序集“Microsoft.Scripting.Core,版本=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 ... 看起来IronPython需要Microsoft.sciting.Core,但对于mono,我不知道该怎么办

  • C#可以在Mono上运行IronPython对象吗?如果可以,怎么做

IronPython不是一个独立的DLL。它有一些应该随IronPython一起提供的依赖项(它们包含在最新的针对.NET 2.0的压缩发行版中--请参阅):

确保您的项目能够找到这些DLL(目前无法找到,这就是为什么会出现错误的原因)

请注意,以.NET 4.0为目标的IronPython版本不包括(或不需要)Microsoft.Scripting.Core.dll和Microsoft.Scripting.ExtensionAttribute.dll,因为它们的功能已合并到
System.Core
。有关详细信息,请参阅

Could not load file or assembly 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Missing method .ctor in assembly /Users/smcho/Desktop/cs/namespace/IronPython.dll, type System.Runtime.CompilerServices.ExtensionAttribute Can't find custom attr constructor image: /Users/smcho/Desktop/cs/namespace/IronPython.dll mtoken: 0x0a000080 Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. ...
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
Microsoft.Scripting.Core.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.ExtensionAttribute.dll