嵌入IronPython的 - 不能添加引用系统 [英] Embedding IronPython - Can't add reference to System
问题描述
我IronPython的嵌入在我的C#应用程序。 出于某种原因,我无法加载程序集。具体而言,我想System.dll中这样我就可以有机会获得.NET类,如日期时间。
I'm embedding IronPython in my C# application. For some reason I'm having trouble loading assemblies. Specifically, I want System.dll so I can have access to .NET classes like DateTime.
如果我试试行:
_runtime.LoadAssembly(_runtime.Host.PlatformAdaptationLayer.LoadAssembly("System"));
我得到:
could not load file or assembly 'System'
如果我明确键入路径为C:/WINDOWS/Microsoft.NET /.../ System.dll中我得到的:
If I explicitly type the path to C:/WINDOWS/Microsoft.NET/.../System.dll I get:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
于是我试着做使用Python脚本中CLR导入:
So then I tried doing the import using clr inside the Python script:
import clr
clr.AddReference('System')
from System import DateTime
和现在我得到:
Cannot import name DateTime
我在哪里去了?为什么日期时间不系统,为什么不能LoadAssembly找到了System.dll?我是否需要显式设置IronPython的一些搜索路径?难道是找到一个无效的'系统'?
Where am I going wrong? Why is DateTime not in System, and why can't LoadAssembly find System.dll? Do I need to explicity set some search paths for IronPython? Is it finding an invalid 'System'?
这一切工作正常,当我测试了IronPython的跨preTER。
This all works fine when I test in the IronPython interpreter.
推荐答案
我用 engine.Runtime.LoadAssembly(typeof运算(字符串).Assembly);
以获得系统装配装;我相信,这是怎样的IronPython的控制台做它。
I use engine.Runtime.LoadAssembly(typeof(string).Assembly);
to get the System assembly loaded; I believe this is how the IronPython console does it as well.
P.S。不要忘记,源IronPython的可用;这是一个金矿这样的东西。
P.S. Don't forget that the source to IronPython is available; it's a gold mine for stuff like this.
这篇关于嵌入IronPython的 - 不能添加引用系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!