IronRuby: Cannot call method on a COM Object with one or more arguments

雨燕双飞 提交于 2020-01-17 03:34:27

问题


When I try and call any method on a COM Object that takes one or more arguments, I get the following error on the last argument:

Could not convert argument 0 for call to Open. (ArgumentError)

Everything works fine when calling a method that takes no arguments, or getting/setting a property. Here is the code that gives me the error above:

def new_com_object(prog_id)
  System::Activator.CreateInstance(System::Type.GetTypeFromProgID(prog_id))
end

xls = new_com_object('Excel.Application')
xls.Visible = true
xls.Workbooks.Open('c:\\Book1.xls')

回答1:


Looks like I need to use String#to_clr_string when calling methods. Right now IronRuby.net documentation is borked, so it's hard to figure that out.



来源:https://stackoverflow.com/questions/2296714/ironruby-cannot-call-method-on-a-com-object-with-one-or-more-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!