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

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


Hi

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";

py.Execute(init);

Entry entry = new Entry();
entry.PrimaryKey.SetValue("Fred");
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";

py.Execute(pyLogic);



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.


-------------------------
Derek

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

_________________________________________________________________
See how Windows Mobile brings your life together—at home, work, or on the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/


More information about the Ironpython-users mailing list