[IronPython] InvalidProgramException exception with NUnit

Dino Viehland dinov at microsoft.com
Mon Sep 29 18:56:45 CEST 2008


What if you create the runtime through IronPython.Hosting.Python.CreateRuntime() instead of reading it from configuration?  Also, does the happen outside of NUnit?

When I change the program to the code below it works for me w/o any issues.  So I'm wondering if it's somehow related to the config you have or if it's related to NUnit doing something which could be altering process state in an unexpected manner.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;
using IronPython.Hosting;

namespace HelloDLRWorld
{
    public class DlrTest
    {
    public static void Main(string[]args) {
        ImportTest();
    }
        public static void ImportTest()
        {
            ScriptRuntime runtime = Python.CreateRuntime();
            runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly);
            runtime.LoadAssembly(typeof(System.Double).Assembly);
            ScriptEngine pyEng = runtime.GetEngine("IronPython");
            ScriptSource source = pyEng.CreateScriptSourceFromString(@"
import System.Diagnostics
output='hello world from DLR/IronPython'
System.Diagnostics.Debug.WriteLine(output)
", SourceCodeKind.Statements);
            ScriptScope scope = pyEng.CreateScope();
            source.Execute(scope);
            object outputMsg = scope.GetVariable("output");
                                Console.WriteLine(outputMsg.ToString());
        }
    }
}



From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Fernando Correia
Sent: Friday, September 26, 2008 12:01 PM
To: Discussion of IronPython
Subject: [IronPython] InvalidProgramException exception with NUnit

I'm upgrading IronPython 2 from B4 to B5 and one of my unit tests is aborting with InvalidProgramException exception in Microsoft.Scripting.Actions.MatchCaller.Call6.

The problem occurs if in the Python statements I try to import anything, no matter what.

No import statement, no error. Also, when executed directly, without a unit test, the same code runs correctly.

Is this a bug?

Source code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;

namespace HelloDLRWorld
{
    [TestFixture]
    public class DlrTest
    {
        [Test]
        public void ImportTest()
        {
            ScriptRuntimeSetup srs = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(srs);
            runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly);
            runtime.LoadAssembly(typeof(System.Double).Assembly);
            ScriptEngine pyEng = runtime.GetEngine("IronPython");
            ScriptSource source = pyEng.CreateScriptSourceFromString(@"
import System.Diagnostics
output='hello world from DLR/IronPython'
System.Diagnostics.Debug.WriteLine(output)
", SourceCodeKind.Statements);
            ScriptScope scope = pyEng.CreateScope();
            source.Execute(scope);
            object outputMsg = scope.GetVariable("output");
            Assert.AreEqual("hello world from DLR/IronPython", outputMsg.ToString());
        }
    }
}

Test result:

------ Test started: Assembly: HelloDLRWorld.exe ------

TestCase 'HelloDLRWorld.DlrTest.ImportTest'
failed: System.InvalidProgramException : Common Language Runtime detectou um programa inválido.
    em Microsoft.Scripting.Actions.MatchCaller.Call6[T0,T1,T2,T3,T4,T5,TRet](Func`8 target, CallSite site, Object[] args)
    em Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
    em Microsoft.Scripting.Actions.UpdateDelegates.Update6[T,T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
    em IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
    em IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
    em <module>$1##1(Closure , Scope , LanguageContext )
    em Microsoft.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression code, Scope scope)
    em Microsoft.Scripting.ScriptCode.Run(Scope scope)
    em Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
    em Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
    C:\Temp\HelloDLRWorld\HelloDLRWorld\HelloDLRWorld\DlrTest.cs(28,0): em HelloDLRWorld.DlrTest.ImportTest()


0 passed, 1 failed, 0 skipped, took 6,47 seconds.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080929/0ad3cd08/attachment.html>


More information about the Ironpython-users mailing list