[IronPython] Unable to cast object of type 'IronPython.Runtime.Types.OldClass' to type 'IronPython.Runtime.Types.DynamicType'

Martin Maly Martin.Maly at microsoft.com
Fri Jul 14 09:44:12 CEST 2006


Thank you very much, great repro, which points to an IronPython bug which I opened on CodePlex (bug 940)

http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=940

in fact, the actual repro is even simpler, no need to declare the TestClass either, simply import minidom and exception happens.

>>> import sys
>>> sys.path.append(r"C:\Python24\Lib")
>>> import xml.dom.minidom
Traceback (most recent call last):
  File , line 0, in <stdin>##8
  File , line 0, in __import__##5
  File C:\Python24\Lib\xml\dom\minidom.py, line 462, in Initialize
TypeError: Unable to cast object of type 'IronPython.Runtime.Types.OldClass' to type 'IronPython.Runtime.Types.DynamicType'.

Martin
________________________________
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Mike Raath
Sent: Friday, July 14, 2006 12:18 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Unable to cast object of type 'IronPython.Runtime.Types.OldClass' to type 'IronPython.Runtime.Types.DynamicType'

OK - I've broken it down to its simplest form. It looks like there's a problem importing the minidom class.

If you create a module TestModule.py containing the following code:

Python Code
==========
import xml.dom.minidom

class TestClass:
    pass


and then try to import this class you will see this error.

My C# code is as follows:
====================
            PythonEngine engine = new PythonEngine();

            engine.AddToPath("C:\\Python24\\lib");
            engine.AddToPath("C:\\Temp\\IronPythonTest\\IronPythonTest\\Python\\");
            engine.Execute("from TestModule import TestClass");


Mike
On 7/13/06, Martin Maly <Martin.Maly at microsoft.com<mailto:Martin.Maly at microsoft.com>> wrote:

However, that said, in Beta 9, the OldClass is no longer a DynamicType, which explains the exception itself. To find out what you need to change in your code is something that we'll need more info for.



For example, the exception can come from anywhere in the Module body (during import, the module body gets executed - unless the module has been already imported). Since I don't get exception when executing "from Module import Class", I suspect that this is what may be the case. The call stack for the exception could help find out what line in your module code is throwing.



M.



________________________________

From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of Martin Maly
Sent: Thursday, July 13, 2006 8:09 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Unable to cast object of type 'IronPython.Runtime.Types.OldClass' to type 'IronPython.Runtime.Types.DynamicType'



To help you, we will need more information about your use of the Python Engine. The simple case of executing "from Module import Class" does work so we need to know more to find out what the problem may be.



Thanks

Martin



________________________________

From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of Mike Raath
Sent: Thursday, July 13, 2006 1:41 AM
To: Discussion of IronPython
Subject: [IronPython] Unable to cast object of type 'IronPython.Runtime.Types.OldClass' to type 'IronPython.Runtime.Types.DynamicType'



Hi

Having tried to switch over to beta 9, and changing my generic Evaluate<T> references to EvaluateAs<T>, I get a runtime error on an import statement which works under beta 8. The exception is as is detailed in the message above, and is from a statement like
engine.Execute("from Module import Class);

The Module and Class definitions are custom - and as i say this statement works under beta 8.

Do you require more information or do I need to make a further change to my code to get it to work?

Thanks,
Mike

_______________________________________________
users mailing list
users at lists.ironpython.com<mailto:users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060714/2e2bf2cd/attachment.html>


More information about the Ironpython-users mailing list