【问题标题】:IronPython Microsoft.Scripting ExceptionIronPython Microsoft.Scripting 异常
【发布时间】:2011-03-08 19:44:32
【问题描述】:

我正在尝试使用 c# 运行 IronPython 代码。 我创建了一个简单的控制台应用程序(.net 4)并添加了 IronPython.dll 、 IronPython.Modules.dll 和 Microsoft.Scripting 并编写了下一个代码 -

using Microsoft.Scripting.Hosting;

namespace app
{
    class Program
    {
        static void Main(string[] args)
        {
            ScriptRuntime runtime = IronPython.Hosting.Python.CreateRuntime();
            ScriptEngine engine = runtime.GetEngine("py");

            engine.Execute("print 'hello!'");
        }
    }
}

在尝试运行此程序时,出现异常 -

未处理的异常: System.Reflection.TargetInvocationException: 异常已被 调用的目标。 ---> System.IO.FileNotFoundException : 无法加载文件或程序集 'Microsoft.Scripting,版本=1.0.0.0, 文化 =中性,PublicKeyToken=31bf3856ad364e35' 或 它的依赖项之一。系统 找不到指定的文件。在 Core.LanguageProvider.Python..ctor(流 流)---内部异常结束 堆栈跟踪 --- 在 System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo 方法,对象 [] 参数, 签名结构&签名, RuntimeType 声明类型)在 System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo 方法,对象 [] 参数, SignatureStruct 签名,RuntimeType 声明类型)在 System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] 参数,CultureInfo 文化)在 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder bin der, Object[] 参数,CultureInfo 文化,对象 [] 激活属性)在 System.Activator.CreateInstance(类型 类型,BindingFlags bindingAttr,Binde r 活页夹,对象 [] 参数,CultureInfo 文化,对象[] 激活属性)在 System.Activator.CreateInstance(类型 类型,对象 [] 参数)在 Core.LanguageRuntime.RegisterLanguageProvider(类型 providerType) 在 D:\cod e\CodeRunner\Core\LanguageRuntime.cs:line 30 在 Test.Program.Main(String[] 参数)在 D:\code\CodeRunner\Test\Program.cs:lin e 19 按任意键继续。 . .

我真的,dont know what to do , searched at google and dont 找到解决方案。 我很乐意得到帮助。

【问题讨论】:

    标签: exception ironpython dynamic-language-runtime


    【解决方案1】:

    您使用的是哪个版本的铁蟒?您显示的语法似乎属于旧版本,现在您应该有类似的内容:

    var ipy = Python.CreateRuntime();
    

    无论如何this blog post 似乎非常准确地指出了正确的使用参考。无论如何,请确保您拥有latest IronPython version.

    【讨论】:

    • 谢谢,解决了。我在尝试同时运行 ironruby 代码和 Ironpython 时遇到另一个问题,我收到此错误,该怎么办?
    • 我不明白回复是否对您有用。无论如何,如果您使用依赖于同一个 DLR 的两个版本,您应该能够同时运行 IronPython 和 IronRuby。不幸的是,我只使用过 IronPython,所以我不能对 Ruby 多说什么。
    • 它对我有用。由于 IronPython 使用 Microsoft.Scripting 2.6 版和 IronRuby 使用 Microsoft.Scripting 1.1 版,我无法同时运行这两个版本,该怎么办?
    • 也许发布一个具体的问题可能会有所帮助。正如我所说,我对 IronRuby 没有直接经验,抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 2010-12-27
    相关资源
    最近更新 更多