[Ironpython-users] Debugging with CLR in Web App

John Davidson jwdavidson at gmail.com
Thu Feb 14 00:47:53 CET 2013


Some more followup detail. I added the Frames and FullFrames option to
the engine creation. This allows me to now get the full stack trace
into the IronPython.dll
The process is hanging in

 	IronPython.dll!IronPython.Runtime.Operations.PythonTypeOps.GetBuiltinFunction(System.Type
type = {Name = Cannot evaluate expression because a native frame is on
top of the call stack. FullName = Cannot evaluate expression because a
native frame is on top of the call stack.}, string cacheName =
"__new__", string pythonName = "__new__",
IronPython.Runtime.Types.FunctionType? funcType = Function |
AlwaysVisible, System.Reflection.MemberInfo[] mems =
{System.Reflection.MemberInfo[3]}) + 0x5e8 bytes

I had also tried enabling the ExceptionDetail, ShowClrExceptions and
MTA options, but they do not change behavior or give any additional
details

John Davidson

On Wed, Feb 13, 2013 at 5:01 PM, John Davidson <jwdavidson at gmail.com> wrote:
> Thank you for the response.
>
> There is no error when running in the debugger. The process just hangs
> at the line "source.Execute(scope)". When I do a manual break in the
> debugger the error I get is "Cannot evaluate expression because a
> native frame is on top of the call stack". The information returned by
> the call stack is incomplete in that the reference to "source.Execute"
> is not included.
>
> IronPython is being loaded only from the GAC and it is the correct
> version 2.7.0.40, reported by the ScriptEngine as being "IronPython
> 2.7.3" when the code is running.
>
> This is not yet running on a target server but is ongoing development
> on VS2012 in Windows 8.
>
> John Davidson
>
> On Wed, Feb 13, 2013 at 11:05 AM, Keith Rome <rome at wintellect.com> wrote:
>> First thing I would check is to make sure it is trying to load the right version of IronPython. If you are deploying the assemblies to your application's bin folder then you will also want to verify that no versions are also loaded in the GAC. Likewise, if your application is using references to GAC'd assemblies then you want to make sure that they are also on the target server (or at least copied to local bin).
>>
>>
>> Other than that, you didn't actually mention what the problem is, or the error message you are seeing. So it will be difficult to offer any help without some information about the problem.
>>
>>
>>
>> Keith Rome
>> Senior Consultant and Architect
>> MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS
>> Wintellect | 770.617.4016 | krome at wintellect.com
>> www.wintellect.com
>>
>> -----Original Message-----
>> From: Ironpython-users [mailto:ironpython-users-bounces+rome=wintellect.com at python.org] On Behalf Of John Davidson
>> Sent: Wednesday, February 13, 2013 9:38 AM
>> To: ironpython-users at python.org
>> Subject: [Ironpython-users] Debugging with CLR in Web App
>>
>> I am in the process of creating an MVC 4 based wiki with scripting support for dynamic creation of content. I have chosen IronPython as the embedded scripting host and am developing a DSL for the scripting portion. This DSL is created in C# and exposed to the CLR for scripting using IronPython.
>>
>> The code I have works correctly when run without debugging. The process for normal execution is w3wp.exe run from VS2012. It also works correctly, with or without debugging, when run as a unit test.
>>
>> The code for script engine creation and execution is shown below:
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Diagnostics;
>> using System.IO;
>> using System.Linq;
>> using System.Reflection;
>> using System.Text;
>> using System.Threading.Tasks;
>> using IronPython.Hosting;
>> using IronPython.Runtime;
>> using Microsoft.Scripting.Hosting;
>>
>> namespace LynxWikiScripting
>> {
>>     public class WikiScriptEngine
>>     {
>>         private static readonly Lazy<WikiScriptEngine> scriptEngine = new Lazy<WikiScriptEngine>(() => { return new WikiScriptEngine(); }, true);
>>
>>         private WikiScriptEngine() {}
>>
>>         public static ScriptEngine Engine = Python.CreateEngine(new Dictionary<string, object>() {{ "Debug", true }} );
>>         public static ScriptRuntime Runtime = Engine.Runtime;
>>         public static ScriptScope scope = Engine.CreateScope();
>>
>>
>>         public static void Initialize()
>>         {
>>             string fullPath = Assembly.GetExecutingAssembly().Location;
>>             string rootDir = Directory.GetParent(fullPath).FullName;
>>
>>         }
>>
>>         public static string ExecuteBehavior(string scriptInput)
>>         {
>>             StringBuilder scriptSource = new StringBuilder();
>>             scriptSource.AppendLine("import clr");
>>             scriptSource.AppendLine(@"clr.AddReferenceToFileAndPath(r'C:\Users\John\Documents\Visual
>> Studio 2012\Projects\LynxWiki\LynxWiki\App_Code\IronWiki.dll')");
>>             scriptSource.AppendLine("import IronWiki");
>>             scriptSource.AppendLine("from IronWiki import UtilityProperties");
>>             scriptSource.AppendLine("from IronWiki import IronWikiSyntax");
>>             scriptSource.Append(scriptInput);
>>             try {
>>                 ScriptSource source =
>> Engine.CreateScriptSourceFromString(scriptSource.ToString(),
>> Microsoft.Scripting.SourceCodeKind.Statements);
>>                 source.Execute(scope);
>>                 var varPyNow = String.Empty;
>>                 scope.TryGetVariable<string>("ScriptOutput", out varPyNow);
>>                 return varPyNow;
>>             }
>>             catch (Exception ex) {
>>                 Debug.Print(ex.Message);
>>                 return ex.Message;
>>             }
>>         }
>>     }
>> }
>>
>> The unit test code is:
>>
>> using System;
>> using System.Text;
>> using Microsoft.VisualStudio.TestTools.UnitTesting;
>> using LynxWikiScripting;
>>
>> namespace LynxWikiScripting.Tests
>> {
>>     [TestClass]
>>     public class UnitTest1
>>     {
>>         [TestMethod]
>>         public void TestIronWikiSyntax()
>>         {
>>             WikiScriptEngine.Initialize();
>>             StringBuilder scriptSource = new StringBuilder();
>>             scriptSource.AppendLine();
>>             scriptSource.AppendLine("WikiSyntax = IronWikiSyntax()");
>>             scriptSource.AppendLine("so = ''");
>>             scriptSource.AppendLine("for iwc in WikiSyntax.IronWikiClasses :");
>>             scriptSource.AppendLine("    so = so + '||' + iwc.Name +
>> '||' + iwc.Description + '''||\\r\\n'''");
>>             scriptSource.AppendLine("ScriptOutput = so");
>>             //scriptSource.AppendLine("");
>>             //scriptSource.AppendLine("");
>>
>>             string result =
>> WikiScriptEngine.ExecuteBehavior(scriptSource.ToString());
>>
>>             Assert.IsNotNull(result);
>>         }
>>     }
>> }
>>
>> The string returned by the processing of the IronPython script is:
>>
>> ||IronWikiSyntax||A class containing information about the IronWiki
>> ||IronWikiSyntax||syntax||
>> ||IronWikiClass||The class describing an IronWiki class||
>> ||IronWikiMember||The class describing an IronWiki member||
>> ||UtilityProperties||A class that provides a number of utility
>> ||UtilityProperties||properties||
>>
>> This is a wiki table text showing the result of reflecting the contents of the DSL at its inception.
>>
>> The application code has identical inputs to ExecuteBehavior as the unit test has. I have tried Python.CreateEngine with or without the "debug" option and also with and without the "trace" option. There is no difference in execution behavior based on having or not having the options included.
>>
>> Is there something else I am missing, or can I give more information to help resolve my problem.
>>
>> Thanks
>>
>> John Davidson
>> _______________________________________________
>> Ironpython-users mailing list
>> Ironpython-users at python.org
>> http://mail.python.org/mailman/listinfo/ironpython-users
>>
>>


More information about the Ironpython-users mailing list