[IronPython] Error only from Test Case

Dino Viehland dinov at microsoft.com
Thu Oct 23 22:38:39 CEST 2008

Are you using NUnit or NDepend?  There's an issue (that we believe is related to how the assemblies are being loaded) which we haven't tracked down just yet: http://www.mail-archive.com/users@lists.ironpython.com/msg07328.html

Running the same code outside of NUnit or NDepend should work.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Matt Beckius
Sent: Thursday, October 23, 2008 1:30 PM
To: users at lists.ironpython.com
Subject: [IronPython] Error only from Test Case

The test below fails (see stacktrace).  If I take the exact same code and execute from a running program,it works just fine.
Any suggestions,


Matt B.

        public void Statements()
            var e = new IPEngine();
            var script = "import System\nfrom System import *\nx = 'kosher'\nprint 'test'";

failed: System.InvalidProgramException : Common Language Runtime detected an invalid program.
            at Microsoft.Scripting.Actions.MatchCaller.Call6[T0,T1,T2,T3,T4,T5,TRet](Func`8 target, CallSite site, Object[] args)
            at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
            at 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)
            at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
            at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
            at <module>$1##1(Closure , Scope , LanguageContext )
            at Microsoft.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression code, Scope scope)
            at Microsoft.Scripting.ScriptCode.Run(Scope scope)
            at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
            at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)

    public class IPEngine
        #region Member Vars

        private readonly ScriptEngine engine;
        private readonly ScriptScope scope;
        private MemoryStream ms;

        #endregion Member Vars

        public IPEngine()
            engine = Python.CreateEngine();
            scope = Engine.CreateScope();

        public ScriptEngine Engine
            get { return engine; }

        public ScriptScope Scope
            get { return scope; }

        public void SetupOutput()
            ms = new MemoryStream();
            engine.Runtime.IO.SetOutput(ms, Encoding.UTF8);
            //engine.Runtime.IO.SetErrorOutput(ms, Encoding.UTF8);

        /// <summary>
        /// Evaluates a single expressoin
        /// </summary>
        /// <typeparam name="T">Return Type</typeparam>
        /// <param name="expression">Expressions to Eval</param>
        /// <returns>T</returns>
        public T Eval<T>(string expression)
            var source = Engine.CreateScriptSourceFromString(expression, SourceCodeKind.Expression);
            return source.Execute<T>(Scope);

        public void Execute(string statements)
            var source = engine.CreateScriptSourceFromString(statements, SourceCodeKind.Statements);

        public string Output
                using (var sr = new StreamReader(ms))
                    ms.Position = 0;
                    return sr.ReadToEnd();

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081023/b007b4b8/attachment.html>

More information about the Ironpython-users mailing list