I am writing an Excel add-in that hosts IronPython 1.1 and I want to provide the Excel.Application COM object to the PythonEngine instance.
My C# can access members of the COM object just fine. However, when my IronPython script accesses members of the COM object, I get a "System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.UInt32&'."
Here is my C# code hosting IronPython 1.1:
public void ExecuteFile(string path) {
// see if COM object works
Debug.WriteLine(Globals.ThisAddIn.Application.ActiveWindow.Caption);
engine.Globals.Add("excel", Globals.ThisAddIn.Application);
try
{
engine.ExecuteFile(path);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
and here is my IronPython test script:
excel.ActiveSheet.Range['A1'].Value2 = 42
// throws exception mentioned above