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 | kr...@wintellect.com
www.wintellect.com

-----Original Message-----
From: Ironpython-users 
[mailto:ironpython-users-bounces+rome=wintellect....@python.org] On Behalf Of 
John Davidson
Sent: Wednesday, February 13, 2013 9:38 AM
To: ironpython-users@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@python.org
http://mail.python.org/mailman/listinfo/ironpython-users


_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
http://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to