In IronPython 2.7.1, I can import some .NET assemblies by name:
>>> from System.Collections import *
>>> from System.IO import *
Others give me an error:
>>> from System.Xml import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Xml
Doing the following fixes the error:
>>> import clr
>>> clr.AddReferenceByPartialName('System.Xml')
>>> from System.Xml import *
Why do I have to call clr.AddReferenceByPartialName for some assemblies but not others?
Some assemblies, like mscorlib.dll, are there by default. If the documentation for the class you want says it’s in mscorlib (e.g., http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx), then you won’t need to add a reference, otherwise you will. It’s similar to when/why you need to add references to your C# project.