[IronPython] clr.AddRefernce* woes

Martin Maly Martin.Maly at microsoft.com
Wed Mar 1 23:40:56 CET 2006


Hi Shawn,

Good to see you playing with IronPython! I may have mentioned it in the talk, or certainly in several hallway discussions, we shipped 1.0 Beta 3 with an unfortunate infinite recursion in the clr.AddReference code.

The bad news is that mostly everyone hits this, the good news (and actually the only reason why we didn't ship refresh immediately right after we discovered the problem) is that there is a workaround.

For System.Xml, you can use (and this is copied from the released 1.0 Beta 3 console:

IronPython 1.0.2237 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReferenceByPartialName("System.Xml")
>>> from System.Xml import *
>>> d = XmlDocument()
>>>

Since the stack overflow also hits the case when you try to pass an assembly directly into the clr.AddReference( ... ), even if Assembly.LoadFrom found your library, you'd hit the bug also.

To import ANY library directly from the file, you can use this code. The trick is to tell IronPython where to look for your DLLs. To do that, you can call:

clr.Path.Add(path)

a special case in the code below being:

clr.Path.Add(System.Environment.CurrentDirectory)


Whole code follows:

C:\IronPython-1.0-Beta3>IronPythonConsole.exe
IronPython 1.0.2237 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> import System
>>> clr.Path.Add(System.Environment.CurrentDirectory)
0
>>> clr.AddReferenceToFile("x.dll")
>>> import Hello
>>> Hello.Method()
'Hello'
>>>

I hope this helps. Again, if it wasn't for these workarounds, we'd have released an update, but as things are now (and with the pre-PyCon craze) we made the call to publicize the workarounds and fix more bugs rather than spend the time on an additional release. We apologize if it was a wrong call. The next release of IronPython will be coming out mid next week so stay tuned.

Martin

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Shawn Wheatley
Sent: Wednesday, March 01, 2006 2:10 PM
To: Discussion of IronPython
Subject: Re: [IronPython] clr.AddRefernce* woes

Hi All!

I just got back from PyCon, where I got to see Martin Maly's talk on
IronPython. I see that Beta 3 is causing quite a bit of problems. I
seem to be having more problems than most, but that may be due to how
I set up my environment. Could someone help me?

Here's what I did:
1) Downloaded the latest IP beta and unpacked to C:\Program
Files\IronPython-1-Beta3
2) Added C:\Program Files\IronPython-1-Beta3 to my path
3) Created a batch file to launch IronPythonConsole:
"C:\Program Files\IronPython-1-Beta3\IronPythonConsole" %1 %2 %3 %4 %5
%6 %7 %8 %9
4) When trying to do any import that involves a reference, I get an error:

C:\Program Files\IronPython-1-Beta3>ipc
IronPython 1.0.2237 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> import System
>>> clr.AddReference(System.Reflection.Assembly.Load('System.Xml'))
Traceback (most recent call last):
  File , line 0, in input##76
IOError: Could not load file or assembly 'System.Xml' or one of its dependencies
. The system cannot find the file specified.
>>> clr.AddReference(System.Reflection.Assembly.LoadFrom('System.Xml'))
Traceback (most recent call last):
  File , line 0, in input##94
IOError: Could not load file or assembly 'file:///C:\Program Files\IronPython-1-
Beta3\System.Xml' or one of its dependencies. The system cannot find the file sp
ecified.
>>> clr.AddReference(System.Reflection.Assembly.LoadWithPartialName('System.Xml'
))

Process is terminated due to StackOverflowException.

C:\Program Files\IronPython-1-Beta3>

If anybody could help me out I'd really appreciate it.

Thanks,
Shawn Wheatley




More information about the Ironpython-users mailing list