IronPython Microsoft.Scripting 异常
我正在尝试使用 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.TargetInitationException: 异常已被抛出 调用的目标。 ---> System.IO.FileNotFoundException: 无法加载文件或程序集 'Microsoft.Scripting,版本=1.0.0.0, 文化 =中性,PublicKeyToken = 31bf3856ad364e35'或 它的依赖项之一。该系统 找不到指定的文件。在 Core.LanguageProvider.Python..ctor(流 Stream) --- 内部异常结束 堆栈跟踪 --- 在 System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo 方法,O object[] args, SignatureStructure&签名, 运行时类型声明类型)位于 System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo 方法,Ob ject[] args, SignatureStruct签名,RuntimeType 声明类型)位于 System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr、B inder 绑定器、Object[] 参数、CultureInfo 文化)位于 System.RuntimeType.CreateInstanceImpl(BindingFlags BindingAttr,Binder bin der,对象[] args,CultureInfo 文化,对象[] 激活属性)位于 System.Activator.CreateInstance(类型 类型、BindingFlags 绑定Attr、Binde r 活页夹,Object[] args,CultureInfo 文化,对象[] 激活属性)位于 System.Activator.CreateInstance(类型 类型,Object[] args)位于 Core.LanguageRuntime.RegisterLanguageProvider(类型 D:\cod 中的providerType) e\CodeRunner\Core\LanguageRuntime.cs:行 30 在 Test.Program.Main(String[] 参数)中 D:\code\CodeRunner\Test\Program.cs:lin e 19 按任意键继续。 。 .
我真的不知道该怎么办,在谷歌搜索但没有找到解决方案。 我会很高兴得到帮助。
I am trying to run IronPython code with c#.
I created a simple console application (.net 4) and added IronPython.dll , IronPython.Modules.dll and Microsoft.Scripting and wrote the next code -
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!'");
}
}
}
While trying to run this , I get an exception -
Unhandled Exception:
System.Reflection.TargetInvocationException:
Exception has been thrown by the
target of an invocation. --->
System.IO.FileNotFoundException :
Could not load file or assembly
'Microsoft.Scripting, Version=1.0.0.0,
Culture
=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The syste m
cannot find the file specified. at
Core.LanguageProvider.Python..ctor(Stream
stream) --- End of inner exception
stack trace --- at
System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo
method, O bject[] args,
SignatureStruct& signature,
RuntimeType declaringType) at
System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo
method, Ob ject[] args,
SignatureStruct signature, RuntimeType
declaringType) at
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags
invokeAttr, B inder binder, Object[]
parameters, CultureInfo culture) at
System.RuntimeType.CreateInstanceImpl(BindingFlags
bindingAttr, Binder bin der, Object[]
args, CultureInfo culture, Object[]
activationAttributes) at
System.Activator.CreateInstance(Type
type, BindingFlags bindingAttr, Binde
r binder, Object[] args, CultureInfo
culture, Object[]
activationAttributes) at
System.Activator.CreateInstance(Type
type, Object[] args) at
Core.LanguageRuntime.RegisterLanguageProvider(Type
providerType) in D:\cod
e\CodeRunner\Core\LanguageRuntime.cs:line
30 at Test.Program.Main(String[]
args) in
D:\code\CodeRunner\Test\Program.cs:lin
e 19 Press any key to continue . . .
I really , dont know what to do , searched at google and don
t find a solution.
I will be glad to get help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是哪个版本的 Iron Python?您显示的语法似乎属于旧版本,现在您应该有类似的内容:
无论如何 这篇博文似乎非常准确地指出了要使用的正确参考。无论如何,请确保您拥有最新的 IronPython 版本。
Whic version of iron python are you using ? The syntax you show seems belong to an older version, now you should have something like:
anyway this blog post seems to be really accurate on pointing the correct reference to use. Anyway, ensure you have the latest IronPython version.