[Ironpython-users] Debugging with CLR in Web App

Keith Rome rome at Wintellect.com
Wed Feb 13 17:05:19 CET 2013

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
Wintellect | 770.617.4016 | krome at 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");
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");
            try {
                ScriptSource source =
                var varPyNow = String.Empty;
                scope.TryGetVariable<string>("ScriptOutput", out varPyNow);
                return varPyNow;
            catch (Exception ex) {
                return ex.Message;

The unit test code is:

using System;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LynxWikiScripting;

namespace LynxWikiScripting.Tests
    public class UnitTest1
        public void TestIronWikiSyntax()
            StringBuilder scriptSource = new StringBuilder();
            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");

            string result =


The string returned by the processing of the IronPython script is:

||IronWikiSyntax||A class containing information about the IronWiki 
||IronWikiClass||The class describing an IronWiki class||
||IronWikiMember||The class describing an IronWiki member||
||UtilityProperties||A class that provides a number of utility 

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.


John Davidson
Ironpython-users mailing list
Ironpython-users at python.org

More information about the Ironpython-users mailing list