我正在将IronPython嵌入到我的C#应用程序中。
由于某些原因,我在加载程序集时遇到了麻烦。具体来说,我想要System.dll,这样我就可以访问.NET类,如DateTime。如果我尝试以下行:
如果我明确地键入路径C:/WINDOWS/Microsoft.NET/.../System.dll,我会得到以下结果:
那么我尝试在Python脚本中使用clr进行导入:
我哪里出错了?为什么 DateTime 不在 System 中,LoadAssembly 找不到 System.dll?我需要明确设置 IronPython 的一些搜索路径吗?它是否找到了无效的“System”?
当我在 IronPython 解释器中测试时,这一切都可以正常工作。
_runtime.LoadAssembly(_runtime.Host.PlatformAdaptationLayer.LoadAssembly("System"));
我得到:
could not load file or assembly 'System'
如果我明确地键入路径C:/WINDOWS/Microsoft.NET/.../System.dll,我会得到以下结果:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
那么我尝试在Python脚本中使用clr进行导入:
import clr
clr.AddReference('System')
from System import DateTime
现在我得到:
Cannot import name DateTime
我哪里出错了?为什么 DateTime 不在 System 中,LoadAssembly 找不到 System.dll?我需要明确设置 IronPython 的一些搜索路径吗?它是否找到了无效的“System”?
当我在 IronPython 解释器中测试时,这一切都可以正常工作。