[IronPython] ArgumentTypeException when accessing C# objects, need help!

Derek Ealy dealy663 at hotmail.com
Tue Sep 23 21:07:01 CEST 2008


I'm pretty new to this whole IronPython thing and have a problem that's been hanging me up for a couple of days now. I have a fairly large C# application, and we've recently added IronPython to the mix so we can support dynamic scripting at runtime.

Users are able to create Python scripts which can manipulate the C# objects in our main application. The problem that I'm having is when I try to pass a C# object to a method on another C# object from within the Python script. It is throwing an ArgumentTypeException: expected Entry got Entry. This is especially confusing, because it sure looks like the exception is saying that an Entry object was expected, and that indeed an Entry object is what it got.

Here is an example of what I'm trying to do:

// C# code

PythonEngine py = new PythonEngine();

string init = "import clr\n" +
         "clr.AddReference(\"TritonConfiguration.dll\")\n" +
         "import TritonConfiguration.ValidationReport as ValidationReport\n" +
         "import TritonConfiguration.Entry as Entry";


Entry entry = new Entry();
Rule rule = new Rule();
rule.Name = "testRule";
py.Globals[“entry”] = entry;
py.Globals["rule"] = rule;

string pyLogic = "if entry.PrimaryKey.Value != 'Barney':\n" +
        "   failure = ValidationReport.RuleFailure('PK is not Barney')\n" +
        "   failure.ruleName = rule.Name\n" +
        "   failure.failedEntry = entry\n";


It is the last line in the pyLogic string that causes the ArgumentTypeException. The failedEntry property of the RuleFailure object is of type Entry. I'm not sure if there is a problem with the way I'm importing things from TritonConfiguration.dll, or the assigning and usage of global variables in Python, or if there's some other thing wrong that I'm completely unaware of.

Any suggestions would be greatly appreciated.


Blogging at: http://derekealy.com/WordPress

See how Windows Mobile brings your life together—at home, work, or on the go.

More information about the Ironpython-users mailing list