Where is open-uri and why it does not work?

I have been trying this for weeks now and still no answer. The open-uri
is messed up in IronRuby. Why does it always keep opening a file and not
the URL?

Here is the error messages:

C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\r
uby\1.8>ir
IronRuby 0.5.0.0 on .NET 2.0.50727.3053
Copyright © Microsoft Corporation. All rights reserved.

require ‘open-uri’
:0:in require': no such file to load -- stringio (LoadError) from ./open-uri.rb:2 from :0 from :0:inrequire’

Why stringio is not present in the same folder as ‘open-uri’?

What???

I am talking about ‘open-uri’ and when I run this:

ir myapp.rb

It throws the exception that it is missing uri and stringio. Why all the
libraries are not put in the same folder why are they distributed in
many different folders?

And there is a file called ‘stringio.rb’

Jim D. wrote:

StringIO is written in C#, so it is part of IronRuby.Libraries.dll. This
is because Ruby’s StringIO has C extensions.

JD

…there is no try

The libraries required by open-uri to function properly are spread up in
two different folders:

paths.Add(@“C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs”);
paths.Add(@“C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8”);

WHY?

StringIO is written in C#, so it is part of IronRuby.Libraries.dll. This
is because Ruby’s StringIO has C extensions.

JD

…there is no try

Thanks for the detailed explanation!

The steps that you have provided worked!

But the main question is that if I am using my project from a different
directory like C:\RubyProject\ and I am also running IR.exe from
C:\RubyProject then how will it find open-uri.

It always says ‘not able to locate open-uri’ file. If I manually add
‘open-uri’ to c:\rubyproject\libs then it complains not able to find
‘uri’

Does it work if you copy open-uri.rb, uri.rb and the uri directory to
C:\rubyproject\libs?

JD

…there is no try

The file stringio.rb (the correct one) has the following in it:


Copyright (c) Microsoft Corporation.

This source code is subject to terms and conditions of the Microsoft

Public License. A

copy of the license can be found in the License.html file at the root

of this distribution. If

you cannot locate the Microsoft Public License, please send an email

to

[email protected]. By using this source code in any fashion, you

are agreeing to be bound

by the terms of the Microsoft Public License.

You must not remove this notice, or any other, from this software.


load_assembly ‘IronRuby.Libraries’, ‘IronRuby.StandardLibrary.StringIO’

There are two library paths in IronRuby. One is the redistribution of
most of the Ruby Standard library. This is the
C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8
folder. The other is IronRuby specific files to load C-based standard
libraries (such as stringio.rb) and stub files to make .NET specific
assemblies easier to load (such as System.Windows.Forms.rb).

For me, the following works from the IronRuby console. Can you send me
the output of it when you try to run it from ir.exe?

C:\vsl\m1\Merlin\Main\Bin\Debug
[26] > ir.exe
IronRuby 0.5.0.0 on .NET 2.0.50727.4908
Copyright (c) Microsoft Corporation. All rights reserved.

puts $:
c:/vsl/m1/Merlin/Main/Languages/Ruby/libs/
c:/vsl/m1/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/site_ruby/1.8/
c:/vsl/m1/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/
.
=> nil
require ‘open-uri’
=> true
u = open(“http://www.google.com”)
=> #<StringIO:0x00000a6 @base_uri=#<URI::HTTP:0x0000096
URL:http://www.google.com>, @meta={“proxy-connection”=>“Keep-Ali
ve”, “connection”=>“Keep-Alive”, “transfer-encoding”=>“chunked”,
“via”=>“1.1 RED-PRXY-27”, “expires”=>“-1”, “date”=>“Mon
, 22 Jun 2009 15:30:20 GMT”, “content-type”=>“text/html;
charset=ISO-8859-1”, “server”=>“gws”, “cache-control”=>“private
, max-age=0”,
“set-cookie”=>“PREF=ID=eb7ab68a47c1cfc2:TM=1245684620:LM=1245684620:S=NVRnVXhGZ3bM1DuD;
expires=Wed, 22-Ju
n-2011 15:30:20 GMT; path=/; domain=.google.com”}, @status=[“200”,
“OK”]>
puts u
#StringIO:0x00000a6
=> nil
u.close
=> nil
exit

Thanks,

JD

…there is no try

What does puts $: output in that situation? I’m wondering why you have
“require ‘libs/open-uri’” instead of “require ‘open-uri’”

JD

…there is no try

It is outputing the following:

puts $:
C:/WINDOWS/system32

Is this one of our releases? Or is it a build from the git sources? In
both cases you should have an ir.exe.config that sets both the libs
folder and the redist-libs folder into your load path. Any idea why
yours doesn’t?

JD

…there is no try

Nope it does not work:

Here is the code:

require ‘libs/System.Windows.Forms’
require ‘libs/System.Drawing’
require ‘libs/open-uri’

The libs folder contains uri.rb which is taken from

C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\ruby-1.8.6p287\lib\ruby\1.8

folder.

And here is the error:

C:\IronRubyProjects\IronRubyTaskListApplication>ir rss_reader_form.rb
:0:in require': no such file to load -- uri (LoadError) from ./libs/open-uri.rb:1 from rss_reader_form.rb:3 from :0:inrequire’

I have even tried running ir.exe from my projects folder:

C:\IronRubyProjects\IronRubyTaskListApplication>ir
IronRuby 0.5.0.0 on .NET 2.0.50727.3053
Copyright © Microsoft Corporation. All rights reserved.

require ‘open-uri’
:0:in `require’: no such file to load – open-uri (LoadError)
from :0

This is downloaded from Git!

I have the ir.exe.config file with the following path setup:

The location of this file is:

C:\ironruby\ironruby\Merlin\Main\bin\Debug

My project location is C:\IronRubyProjects\IronRubyTaskListApplication.

I am running the IR.EXX from
C:\IronRubyProjects\IronRubyTaskListApplication and then it complains
about the open-uri file. I put the open-uri file in the libs folder then
is complains about uri file. I put the uri file and uri folder in the
libs folder but it still complains about the uri file.

Can you run c:\ironruby\ironruby\Merlin\Main\bin\debug\ir.exe
C:\IronRubyProjects\IronRubyTasksApplication\foo.rb (where foo is the
startup file for your program)?

JD

…there is no try

I should also mention one thing which is that I placed my ir.exe and
some other files that are required by ir.exe in System32 folder so that
I can access it from anywhere in the directory.

No I cannot run it because it require Windows.Forms and Windows.Drawing
modules. If I add those modules then it will work:

C:\ironruby\ironruby\Merlin\Main\bin\Debug>ir.exe
C:\IronRubyProjects\IronRubyTa
skListApplication\main_form.rb
C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\Builtin
s\KernelOps.cs:423:in `require’: no such file to load –
libs/System.Windows.For
ms (LoadError)
from
C:/IronRubyProjects/IronRubyTaskListApplication/main_form.rb:2

A better way to do that, in this case, is to just add
c:\ironruby\ironruby\Merlin\Main\bin\debug to your %PATH%

JD

…there is no try

How do I do that?