There's an inner exception here (probably from Importer.cs in MakeImportSite) but there isn't much info on it. Could you run it under a debugger and get that original stack trace? It's not clear to me why we would blow up there.
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fernando Correia Sent: Wednesday, March 12, 2008 7:54 AM To: [email protected] Subject: [IronPython] InvalidProgramException testing hosting under NUnit I have a small hosting class that works on a WinForms app. But it gives an InvalidProgramException when called from a NUnit test. The test project is within the IronPython solution and I've referenced IronPython, IronPython.Modules and Microsoft.Scripting. I'd like to know if other people were able to test hosting using NUnit. Thanks. ********** This is the error report: ********** ------ Test started: Assembly: HostingTest.dll ------ TestCase 'HostingTest.Class1.TestHosting' failed: Microsoft.Scripting.InvalidImplementationException : Type 'IronPython.Runtime.PythonContext' doesn't provide a suitable public constructor or its implementation is faulty. ----> System.TypeInitializationException : O inicializador de tipo de 'IronPython.Runtime.Importer' acionou uma exceção. ----> System.InvalidProgramException : Common Language Runtime detectou um programa inválido. C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\Microsoft.Scripting\Utils\ReflectionUtils.cs(129,0): em Microsoft.Scripting.Utils.ReflectionUtils.CreateInstance[T](Type actualType, Object[] args) C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\Microsoft.Scripting\ScriptDomainManager.cs(276,0): em Microsoft.Scripting.ScriptDomainManager.LanguageRegistration.LoadLanguageContext(ScriptDomainManager manager) C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\Microsoft.Scripting\ScriptDomainManager.cs(387,0): em Microsoft.Scripting.ScriptDomainManager.TryGetLanguageContext(String languageId, LanguageContext& languageContext) C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\Microsoft.Scripting\ScriptDomainManager.cs(437,0): em Microsoft.Scripting.ScriptDomainManager.GetEngine(String languageId) C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\Microsoft.Scripting\Hosting\ScriptEnvironment.cs(156,0): em Microsoft.Scripting.Hosting.ScriptEnvironment.GetEngine(String languageId) C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\HostingTest\Host.cs(11,0): em HostingTest.Host.Teste() C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\HostingTest\Class1.cs(12,0): em HostingTest.Class1.TestHosting() --TypeInitializationException em IronPython.Runtime.Importer..ctor(PythonContext context) C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\IronPython\Runtime\PythonContext.cs(120,0): em IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager) --InvalidProgramException em Microsoft.Scripting.RuntimeHelpers.CreateSimpleCallSite[T0,T1,T2,T3,T4,R]() C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\IronPython\Runtime\Importer.cs(74,0): em IronPython.Runtime.Importer.MakeImportSite() C:\Temp\IronPython v2.0 Alpha 8\IronPython-2.0A8-Src\IronPython-2.0A8\Src\IronPython\Runtime\Importer.cs(49,0): em IronPython.Runtime.Importer..cctor() 0 passed, 1 failed, 0 skipped, took 2,11 seconds. ********** Class1.cs ********** using NUnit.Framework; namespace HostingTest { [TestFixture] public class Class1 { [Test] public void TestHosting() { Host host = new Host(); string x = host.Test(); Assert.AreEqual("Hosting", x); } } } ********** Host.cs ********** using Microsoft.Scripting; using Microsoft.Scripting.Hosting; namespace HostingTest { public class Host { public string Test() { IScriptEnvironment env = ScriptEnvironment.GetEnvironment(); IScriptEngine pe = env.GetEngine("py"); IScriptScope scope = env.CreateScope(); SourceUnit script = pe.CreateScriptSourceFromString(@" def Test(): return 'Hosting' ", SourceCodeKind.Statements); CompiledCode codigo = (CompiledCode)pe.Compile(script); codigo.Execute(scope); SourceUnit function = pe.CreateScriptSourceFromString("Test()"); CompiledCode funcao = (CompiledCode)pe.Compile(function); return funcao.Evaluate(scope).ToString(); } } }
_______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
