[IronPython] sys.LoadAssembly* changes in 1.0 Beta 1

Martin Maly Martin.Maly at microsoft.com
Tue Jan 3 01:52:32 CET 2006


One of the design issues that followed IronPython pretty much since the very beginning was to find correct place for the two methods we added into the built-in sys module - sys.LoadAssemblyFromFile and sys.LoadAssemblyByName. The downsides were not only that these methods didn't belong to the built-in sys module, but also the assemblies were loaded by specifying file name or partial assembly name only and there was not a way to load assembly given strong assembly name.

In 1.0 Beta 1 we changed the way .NET assemblies are loaded - or referenced. The new model is inspired by the Python's sys.path and import behavior. However, unlike sys.path, which usually contains list of directories, the IronPython references are list (currently tuple, actually) of .NET assemblies. This part was inspired by the assembly references passed to .NET compilers.

First, we added a module "clr" which contains the functions to add references to .NET assemblies:

* AddReference
* AddReferenceToFile
* AddReferenceByName
* AddReferenceByPartialName

They allow adding references to the .NET assemblies by specifying strong assembly name (AddReferenceByName), partial assembly name (AddReferenceByPartialName - formerly sys.LoadAssemblyByName), assembly file (AddReferenceToFile - formerly sys.LoadAssemblyFromFile) or by providing the assembly object (instance of System.Reflection.Assembly) itself (AddReference).

AddReference not only adds reference to the assembly object, but also provides convenient way to add reference to the assembly by specifying file name, partial name or strong assembly name. If string argument is passed to AddReference, IronPython will try to interpret it first as strong assembly name, file name or partial assembly name. As a result the function may not give unambiguous results when passing string as a parameter (Susan Cook's blog explains more on this http://blogs.msdn.com/suzcook/archive/2003/05/30/57159.aspx). Using AddReference with string parameter is therefore suitable for interactive console, quick prototypes etc, but we recommend using AddReferenceByName or AddReferenceToFile for the longer-lasting scripts.

clr module also has an attribute "References" - a tuple containing all referenced assemblies. While it is a tuple for now, this may - and probably will - change. We view this tuple as the list of assemblies that IronPython searches to find .NET namespaces being imported.

For 1.0 Beta 1 we are keeping the sys.LoadAssembly* functions, but encourage you to start using the clr.AddReference* and give us feedback. For Beta 2 we will probably make sys.LoadAssembly* obsolete and will eventually remove them completely.

As for the clr.AddReference*, we hope that we are getting closer to the right solution. Nonetheless, lease let us know what you would like to see changed, improved, or added.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060102/20792cf8/attachment.html>

More information about the Ironpython-users mailing list