5

IronRuby 帮助网站上的此页面讨论了能够“需要”一些众所周知的程序集,例如 System.Windows.Forms 而无需完成整个 ' ah-come-on-gimme-a-break-here-you -cannot-be-serious ' 程序集的强名称。

在文档中它是这样说的:

>>> require "System.Windows.Forms"  
=> true  

但是当我尝试相同的“要求”时,我得到了这个:

>>> require "System.Windows.Forms"
IronRuby.Libraries:0:in 'require': no such file to load -- System.Windows.Forms (LoadError) 
        from :0:in 'Initialize##1'

我可能做错了什么?会不会是设置问题?我看不到文档中提到的这个“加载路径上的 libs 目录”。文档有错吗?

谢谢。

4

2 回答 2

7

之所以如此,是因为 IronRuby 的人已经编写了一堆包装脚本。

往里看<your ironruby install path>\lib\ironruby,你会看到System.Windows.Forms.rb等等System.Drawing.rb

当您这样做时require 'System.Windows.Forms',IronRuby 会找到该 rb 文件并运行它。该文件中的代码只是为您执行完整的强名称要求。

如果您想加载他们没有为其编写包装器的其他 dll,您有 3 个选项:

  1. 需要 dll 的完整路径(例如c:\program files\whatever\whatever\blah.dll

  2. 需要强名称(这仅适用于 GAC 或 IronRuby 可以在其中找到 dll 的其他地方)

  3. 使用load_assembly- 这是最方便的,但 IIRC 它将 dll 加载到LoadFrom上下文中,而不是Load上下文中。
    如果您不明白这意味着什么,那么基本上在测试中没问题,但不要在生产中这样做:-)

于 2010-02-28T19:55:33.853 回答
2

嗯,这一个设置问题 - IronRuby 下载中有两个 ir.exe 副本,而我使用了错误的副本。

于 2010-02-03T20:52:00.603 回答