【问题标题】:IronPython, import, and clr.AddReferenceByPartialNameIronPython、导入和 clr.AddReferenceByPartialName
【发布时间】:2012-03-03 02:04:08
【问题描述】:

IronPython 2.7.1 中,我可以按名称导入一些 .NET 程序集:

>>> from System.Collections import *
>>> from System.IO import *

别人给我报错:

>>> from System.Xml import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Xml

执行以下操作可修复错误:

>>> import clr
>>> clr.AddReferenceByPartialName('System.Xml')
>>> from System.Xml import *

为什么我必须为某些程序集调用 clr.AddReferenceByPartialName 而对其他程序集却不调用?

【问题讨论】:

    标签: .net ironpython


    【解决方案1】:

    一些程序集,例如 mscorlib.dll,默认情况下存在。如果你想要的类的文档说它在 mscorlib 中(例如,http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx),那么你不需要添加引用,否则你会。这类似于何时/为什么需要添加对 C# 项目的引用。

    【讨论】: