This indicates we're generating invalid IL. The best way to debug this is to enable the SaveAssemblies option which will cause us to save the code to disk. Programmatically you can do this via Snippets.Shared.SaveSnippets = true. When the process is finished you should then call Snippets.Shared.Dump() which will write the assemblies to disk. From there you can run peverify on the assemblies and report back what the invalid IL is and what the verification error is.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Hall Sent: Saturday, May 17, 2008 7:51 AM To: Discussion of IronPython Subject: Re: [IronPython] Custom Host - Import CLR fails Hi Dino, Thanks for your reply. Spent all day trying to debug the problem. I have the code working in a POC, I have it working in my UI but my unit tests are failing. The exception being raised is (different to before): Unhandled Exception System.TypeInitializationException: The type initializer for 'IronPython.Runtime.Importer' threw an exception. ---> System.InvalidProgramException: Common Language Runtime detected an invalid program. at Microsoft.Scripting.Actions.CallSiteFactory.CreateSimpleCallSite[T0,T1,T2,T3,T4,T5,R](ActionBinder binder) at IronPython.Runtime.Importer.MakeImportSite() at IronPython.Runtime.Importer..cctor() --- End of inner exception stack trace --- 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 Initialize##1(Closure , CodeContext ) at Microsoft.Scripting.ScriptCode.Run(CodeContext context, Boolean tryEvaluate) at Microsoft.Scripting.ScriptCode.Run(Scope scope, Boolean tryEvaluate) at Microsoft.Scripting.ScriptCode.Run(Scope scope) at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) at Microsoft.Scripting.SourceUnit.Execute(Scope scope) at Microsoft.Scripting.Hosting.ScriptScope.Execute(String code) Information wrote to Debug window: 'ProcessInvocation.exe' (Managed): Loaded 'Snippets' 'ProcessInvocation.exe' (Managed): Loaded 'Snippets' 'ProcessInvocation.exe' (Managed): Loaded 'Anonymously Hosted DynamicMethods Assembly' A first chance exception of type 'System.TypeInitializationException' occurred in Unknown Module. Any tips on how I can get to the bottom of this? Thanks Ben On Sat, May 17, 2008 at 3:01 AM, Dino Viehland <[EMAIL PROTECTED]> wrote: > This works for me in IronPython 2.0B2: > > using System; > using System.Reflection; > > using Microsoft.Scripting; > using Microsoft.Scripting.Hosting; > > class Test { > public static void Main(string[]args) { > ScriptRuntime runtime = ScriptRuntime.Create(); > ScriptEngine engine = runtime.GetEngine("py"); > > runtime.LoadAssembly(typeof(string).Assembly); > runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); > > Assembly assem = > Assembly.GetAssembly(Type.GetType("System.Text.StringBuilder")); > engine.Runtime.LoadAssembly(assem); > > //ScriptSource code = engine.CreateScriptSourceFromString("import > clr\n", SourceCodeKind.File); > ScriptScope source = engine.CreateScope(); > source.Execute("import clr\nprint clr\nimport > System\nSystem.Console.WriteLine('hello world')\n"); > > } > } > > It prints: > > <module 'clr' (built-in)> > hello world > > Do you still get an exception with this code? I also realize you were trying > to load them dynamically on another thread but it might be worth pointing out > this doesn't actually end up w/ any dependencies on IronPython.dll or > IronPython.Modules.dll as written. > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Hall > Sent: Friday, May 16, 2008 6:09 PM > To: Discussion of IronPython > Subject: [IronPython] Custom Host - Import CLR fails > > Hi, > > After getting Python code to work successfully, I decided to quickly > import the CLR and access some .Net objects. At this point my code > blew up. > The code I tried to execute was "import clr". > > Exception is this: > > Unhandled Exception System.NullReferenceException: Object reference > not set to an instance of an object. > at Microsoft.Scripting.Utils.SlowReflectedCaller.InvokeInstance(Object > instance, Object[] args) > at > Microsoft.Scripting.Actions.ActionBinder.UpdateSiteAndExecute[T](CodeContext > context, CallSite`1 site, Object[] args) > at > Microsoft.Scripting.Actions.UpdateDelegates.Update5[T0,T1,T2,T3,T4,TRet](CallSite > site, CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 > arg4) > at Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext > context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) > 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 Initialize##1(Closure , CodeContext ) > at Microsoft.Scripting.ScriptCode.Run(CodeContext context, Boolean > tryEvaluate) > at Microsoft.Scripting.ScriptCode.Run(Scope scope, Boolean tryEvaluate) > at Microsoft.Scripting.ScriptCode.Run(Scope scope) > at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) > at Microsoft.Scripting.SourceUnit.Execute(Scope scope) > at Microsoft.Scripting.Hosting.ScriptScope.Execute(String code) > at MyApp.Engine.ScriptExecutor.ExecuteStatement(String code) > > After a bit of search, I found that you don't load mscorlib for us. > > I have tried 3 different ways to import the assemblies everyone says I > need to load: > > ScriptRuntime runtime = ScriptRuntime.Create(); > ScriptEngine engine = runtime.GetEngine(); > > LanguageContext Language = > HostingHelpers.GetLanguageContext(engine); > Language.DomainManager.LoadAssembly(typeof(string).Assembly); > > Language.DomainManager.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); > > runtime.LoadAssembly(typeof(string).Assembly); > runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); > > Assembly assem = > Assembly.GetAssembly(Type.GetType("System.Text.StringBuilder")); > engine.Runtime.LoadAssembly(assem); > > To execute the code, I do this: > ScriptScope source = Engine.CreateScope(); > source.Execute(code); > > However nothing, I still get the exception. > > Any suggestions on where I am going wrong? > > Thanks > > Ben Hall > Blog.BenHall.me.uk > _______________________________________________ > Users mailing list > Users@lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users@lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com