1

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 dont find a solution. I will be glad to get help.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks,fixed it out . I have another problem when trying to run both ironruby code and ironpython,I am getting this error, what to do?
I did not understand if the reply was working for you or not. Anyway you should be able to run both IronPython and IronRuby if you use two version depending on the same DLR. Unfortunately I've only experience with IronPython so I can't say anything more about Ruby.
It worked for me. I can`t run both because IronPython uses Microsoft.Scripting version 2.6 and IronRuby using Microsoft.Scripting version 1.1, what to do?
maybe posting a question specific on this could help. As I said I've no direct experience with IronRuby, sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.