IronPython Microsoft.Scripting Exception
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.P开发者_开发技巧ython.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.
Whic version of iron python are you using ? The syntax you show seems belong to an older version, now you should have something like:
var ipy = Python.CreateRuntime();
anyway this blog post seems to be really accurate on pointing the correct reference to use. Anyway, ensure you have the latest IronPython version.
精彩评论