[IronPython] wierd import problem

Dino Viehland dinov at exchange.microsoft.com
Mon Apr 23 22:49:13 CEST 2007


I haven't had a chance to track down what the underlying problem here is (and suspect this is a bug), but is there a reason you can't do:

>>> import clr
>>> clr.AddReference('Foo.bar.dll')
>>> import Foo.Bar

This seems to work.  The only reason to use AddReferenceToFile is really if you are dealing with assemblies that live outside of your app domain base.  In that case AddReferenceToFile will attempt to use sys.path to search for referenced assemblies when the CLR loader attempts to load them.

But if you're using this DLL from within your app domain base then doing AddReference will cause the CLR to do an Assembly.Load('foo.bar.dll') which will succeed and also get the dependencies using the standard .NET way.

Let me know if this is a reasonable workaround for you and I'll continue to look into the underlying issue here.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tony Djordjevski
Sent: Monday, April 23, 2007 12:36 PM
To: users at lists.ironpython.com
Subject: [IronPython] wierd import problem

Hi everyone,

I'm seeing a bit of weirdness when trying to import a dll with a nested namespace.  Actually, I'm not sure if it's a filename issue or a namespace issue, as the filename of the assembly is named after the namespace.

OK, let's say I have two assemblies: Foo.exe and Foo.Bar.dll (I've attached a simple Visual Studio project to recreate the situation)

I want to "import Foo.Bar", but I'm getting an error concerning Foo.exe

Here's the steps to reproduce:

 >>> import clr
 >>> clr.AddReferenceToFile('Foo.Bar.dll')
 >>> import Foo.Bar
Traceback (most recent call last):
   File , line 0, in <stdin>##14
   File , line 0, in __import__##7
SystemError: C:\Temp\Foo\bin\Debug\Foo.exe is not pre-compiled module; try again after deleting it.
 >>> for ref in clr.References:
...     print ref
...
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Foo.Bar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null  >>>

As the output shows, Foo.Bar has been referenced.  So what am I doing wrong that I can't import?

BTW, I'm using IP v1.1 (in case you're wondering).

Thanks,
Tony




More information about the Ironpython-users mailing list