【问题标题】:IronRuby - how to require .NET assemblies without strong name?IronRuby - 如何要求没有强名称的 .NET 程序集?
【发布时间】:2010-02-03 17:36:18
【问题描述】:

This page 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 目录”。文档有错吗?

谢谢。

【问题讨论】:

    标签: ironruby require


    【解决方案1】:

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

    查看<your ironruby install path>\lib\ironruby,您会看到System.Windows.Forms.rbSystem.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 上下文中。
      如果你不明白这意味着什么,那么基本上它在测试中是可以的,但不要在生产中这样做:-)

    【讨论】:

    • 谢谢 - 看看 IronRuby 人是如何实现这个的很有趣。
    • 我有一个不同的问题,使用load_assembly 解决了它。在哪里可以找到有关requireload_assembly 之间差异的更多详细信息?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      相关资源
      最近更新 更多