Forum: IronRuby Open-Uri Path in App.Config

Posted by Mohammad Azam (azamsharp)
on 2010-03-01 02:21
I completely forgot the paths that I need to setup to use open-uri in
IronRuby when using with C#. I need to put those paths in my App.config
to work with open-uri. Can anyone please paste those sections here? I
keep forgetting those sections that I need to include in my App.config.
Posted by Shay Friedman (shayfriedman)
on 2010-03-01 06:30
(Received via mailing list)
I guess you're talking about that:
<options>
  <set language='Ruby' option='LibraryPaths'
value='..\lib\IronRuby;..\lib\ruby\site_ruby\1.8;..\lib\ruby\site_ruby;..\lib\ruby\1.8'/>
</options>

Shay.
--------------------------------------------------------
Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed 
|
Sela Technology Center
Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay
Posted by Ivan Porto Carrero (Guest)
on 2010-03-01 09:44
(Received via mailing list)
Is this still an issue?

Provide a config file like this:

<?xml version='1.0' encoding='UTF-8'?>
<configuration>
  <configSections>
    <section name='microsoft.scripting' requirePermission='false'
type='Microsoft.Scripting.Hosting.Configuration.Section,
Microsoft.Scripting, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'/>
  </configSections>

  <microsoft.scripting>
    <languages>
      <language extensions='.py' displayName='IronPython 2.6.1'
type='IronPython.Runtime.PythonContext, IronPython, Version=2.6.10920.0,
Culture=neutral, PublicKeyToken=null' names='IronPython;Python;py'/>
      <language extensions='.rb' displayName='IronRuby'
type='IronRuby.Runtime.RubyContext, IronRuby, Version=0.9.4.0,
Culture=neutral, PublicKeyToken=null' names='IronRuby;Ruby;rb'/>
    </languages>

    <options>
      <set language='Ruby' option='LibraryPaths'
value='C:\ironruby\lib\IronRuby;C:\ironruby\lib\ruby\site_ruby\1.8;C:\ironruby\lib\ruby\site_ruby;C:\ironruby\lib\ruby\1.8'/>
    </options>
  </microsoft.scripting>
</configuration>



Host IronRuby like this:

var setup = ScriptRuntimeSetup.ReadConfiguration();
scriptRuntime = Ruby.CreateRuntime(setup);
Engine = Ruby.GetEngine(Runtime);
Context = Ruby.GetExecutionContext(Engine);
// You can use Context.Loader.SetLoadPaths(IEnumerable<string> paths) to
replace the load paths at run-time
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 15:25
So, I added the paths that you provided in my C# code since I am trying 
to execute the .rb file from C#. Here is the complete code:

  static void Main(string[] args)
        {
            var url = "http://www.google.com.com";

            var engine = IronRuby.Ruby.CreateEngine();
            var scope = engine.ExecuteFile("../../screenscraper.rb");

            var paths = new List<String>();
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby\1.8");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\1.8");


            engine.SetSearchPaths(paths);


            var obj = 
engine.Runtime.Globals.GetVariable("ScreenScraper");

            var screenScraper = engine.Operations.CreateInstance(obj);

            var html = engine.Operations.InvokeMember(screenScraper, 
"scrape", url);

            Console.WriteLine(html);

        }


When I run the application I get the following error:


Unhandled Exception: IronRuby.Builtins.LoadError: no such file to load 
-- open-u
ri
   at 
Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame 
fram
e)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame 
frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 
arg0, T1 a
rg1)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope, Boolean 
bindGlobals)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink 
errorSink)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope 
scope)
   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)
   at IronRubyConsoleApp.Program.Main(String[] args) in 
C:\Projects\ILoveIronRub
y\ILoveIronRuby\IronRubyConsoleApp\Program.cs:line 15
Press any key to continue . . .


Posted by Ivan Porto Carrero (Guest)
on 2010-03-01 15:37
(Received via mailing list)
you might want to move the executefile method

var url = "http://www.google.com.com";

           var engine = IronRuby.Ruby.CreateEngine();


           var paths = new List<String>();
           paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");

 paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby\1.8");
           paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby");
           paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\1.8");


           engine.SetSearchPaths(paths);


           var obj =
engine.Runtime.Globals.GetVariable("ScreenScraper");
           engine.ExecuteFile("../../screenscraper.rb");
           var screenScraper = engine.Operations.CreateInstance(obj);

           var html = engine.Operations.InvokeMember(screenScraper,
"scrape", url);

           Console.WriteLine(html);
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero - Mob: +32.486.787.582
Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Microsoft IronRuby/C# MVP
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 16:21
Here is my implementation:

 static void Main(string[] args)
        {
            var url = "http://www.google.com";

            var engine = IronRuby.Ruby.CreateEngine();

            var paths = new List<String>();
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby\1.8");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\1.8");


            engine.SetSearchPaths(paths);

            engine.ExecuteFile("../../screenscraper.rb");
            var obj = 
engine.Runtime.Globals.GetVariable("ScreenScraper");

            var screenScraper = engine.Operations.CreateInstance(obj);

            var html = engine.Operations.InvokeMember(screenScraper, 
"scrape", url);

            Console.WriteLine(html);

        }


And now it throws the following error:


Unhandled Exception: IronRuby.Builtins.LoadError: no such file to load 
-- string
io
   at 
Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame 
fram
e)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame 
frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 
arg0, T1 a
rg1)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope, Boolean 
bindGlobals)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink 
errorSink)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope 
scope)
   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)
   at IronRubyConsoleApp.Program.Main(String[] args) in 
C:\Projects\ILoveIronRub
y\ILoveIronRuby\IronRubyConsoleApp\Program.cs:line 25
Press any key to continue . . .





Ivan Porto Carrero wrote:
> you might want to move the executefile method
> 
> var url = "http://www.google.com.com";
> 
>            var engine = IronRuby.Ruby.CreateEngine();
> 
> 
>            var paths = new List<String>();
>            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
> 
>  paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby\1.8");
>            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby");
>            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\1.8");
> 
> 
>            engine.SetSearchPaths(paths);
> 
> 
>            var obj =
> engine.Runtime.Globals.GetVariable("ScreenScraper");
>            engine.ExecuteFile("../../screenscraper.rb");
>            var screenScraper = engine.Operations.CreateInstance(obj);
> 
>            var html = engine.Operations.InvokeMember(screenScraper,
> "scrape", url);
> 
>            Console.WriteLine(html);
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero - Mob: +32.486.787.582
> Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
> Microsoft IronRuby/C# MVP
Posted by Jim Deville (Guest)
on 2010-03-01 16:46
(Received via mailing list)
You need to include the rest of the ironruby search paths. For example. 
"C:\devtools\ironruby-1.0-rc1\lib\ironruby"

Also, the ir.exe.config from c:\devtools\ironruby-1.0-rc1\bin should be 
setup exactly like you want. If you provide that to your app it should 
just work. That's why we install that config file.

JD
Posted by Ivan Porto Carrero (Guest)
on 2010-03-01 16:51
(Received via mailing list)
here's an idea maybe buy my book. All this is explained in there

replace: paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
with: paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ironruby");

That's the location that contains stringio.rb.

It was like this when I sent the email earlier: <set language='Ruby'
option='LibraryPaths' value='*C:\ironruby\lib\IronRuby*
;C:\ironruby\lib\ruby\site_ruby\1.8;C:\ironruby\lib\ruby\site_ruby;C:\ironruby\lib\ruby\1.8'/>

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Microsoft IronRuby/C# MVP
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 16:52
I copied the ironruby config file into my application's config file and 
removed all the path variables from my application but it did not work. 
Then I added the "C:\devtools\ironruby-1.0-rc1\lib\ironruby" path and 
removed the app.config and then it worked out.

Any ideas that why even copy pasting the app.config from ironruby to my 
application app.config did not work?


Jim Deville wrote:
> You need to include the rest of the ironruby search paths. For example. 
> "C:\devtools\ironruby-1.0-rc1\lib\ironruby"
> 
> Also, the ir.exe.config from c:\devtools\ironruby-1.0-rc1\bin should be 
> setup exactly like you want. If you provide that to your app it should 
> just work. That's why we install that config file.
> 
> JD
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 16:53
I will definitely buy your book when IronRuby is publicly released! I 
don't want to consult the book and find out that opps that has now 
changed in the final release.

Ivan Porto Carrero wrote:
> here's an idea maybe buy my book. All this is explained in there
> 
> replace: paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
> with: paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ironruby");
> 
> That's the location that contains stringio.rb.
> 
> It was like this when I sent the email earlier: <set language='Ruby'
> option='LibraryPaths' value='*C:\ironruby\lib\IronRuby*
> ;C:\ironruby\lib\ruby\site_ruby\1.8;C:\ironruby\lib\ruby\site_ruby;C:\ironruby\lib\ruby\1.8'/>
> 
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
> Microsoft IronRuby/C# MVP
Posted by Jim Deville (Guest)
on 2010-03-01 17:08
(Received via mailing list)
a)IronRuby is in the home stretch.
b)Ivan's book is keeping up with the development, and if you buy the 
Manning EAP beta, you will get the updates and have the option to get 
the final copy.
JD
Posted by Jim Deville (Guest)
on 2010-03-01 17:28
(Received via mailing list)
Probably because your app config is in a different location than ir.exe.

Try this. Replace:

static void Main(string[] args)
        {
            var url = "http://www.google.com";

            var engine = IronRuby.Ruby.CreateEngine();

            var paths = new List<String>();
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby\1.8");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby");
            paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\1.8");


            engine.SetSearchPaths(paths);

            engine.ExecuteFile("../../screenscraper.rb");
            var obj =
engine.Runtime.Globals.GetVariable("ScreenScraper");

            var screenScraper = engine.Operations.CreateInstance(obj);

            var html = engine.Operations.InvokeMember(screenScraper,
"scrape", url);

            Console.WriteLine(html);

        }
With:

static void Main(string[] args)
        {
            var url = "http://www.google.com";
            var setup = ScriptRuntimeSetup.ReadConfiguration();
            var scriptRuntime = Ruby.CreateRuntime(setup);
            var engine = Ruby.GetEngine(Runtime);
            //the following line might not be needed in this case
             var context = Ruby.GetExecutionContext(Engine);

            engine.ExecuteFile("../../screenscraper.rb");
            var obj =
engine.Runtime.Globals.GetVariable("ScreenScraper");

            var screenScraper = engine.Operations.CreateInstance(obj);

            var html = engine.Operations.InvokeMember(screenScraper,
"scrape", url);

            Console.WriteLine(html);

        }
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 17:38
Hi,

>> Probably because your app config is in a different location than ir.exe.

Do you mean the ironruby app config or my application app config? My 
application config is in my application directory. The question is that 
why it is not reading my application config automatically.

Thanks,
Azam


Jim Deville wrote:
> Probably because your app config is in a different location than ir.exe.
> 
> Try this. Replace:
> 
> static void Main(string[] args)
>         {
>             var url = "http://www.google.com";
> 
>             var engine = IronRuby.Ruby.CreateEngine();
> 
>             var paths = new List<String>();
>             paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib");
>             paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby\1.8");
>             paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\site_ruby");
>             paths.Add(@"C:\DevTools\ironruby-1.0-rc1\lib\ruby\1.8");
> 
> 
>             engine.SetSearchPaths(paths);
> 
>             engine.ExecuteFile("../../screenscraper.rb");
>             var obj =
> engine.Runtime.Globals.GetVariable("ScreenScraper");
> 
>             var screenScraper = engine.Operations.CreateInstance(obj);
> 
>             var html = engine.Operations.InvokeMember(screenScraper,
> "scrape", url);
> 
>             Console.WriteLine(html);
> 
>         }
> With:
> 
> static void Main(string[] args)
>         {
>             var url = "http://www.google.com";
>             var setup = ScriptRuntimeSetup.ReadConfiguration();
>             var scriptRuntime = Ruby.CreateRuntime(setup);
>             var engine = Ruby.GetEngine(Runtime);
>             //the following line might not be needed in this case
>              var context = Ruby.GetExecutionContext(Engine);
> 
>             engine.ExecuteFile("../../screenscraper.rb");
>             var obj =
> engine.Runtime.Globals.GetVariable("ScreenScraper");
> 
>             var screenScraper = engine.Operations.CreateInstance(obj);
> 
>             var html = engine.Operations.InvokeMember(screenScraper,
> "scrape", url);
> 
>             Console.WriteLine(html);
> 
>         }
Posted by Jim Deville (Guest)
on 2010-03-01 17:54
(Received via mailing list)
Is app.config in the same directory as c:\path\to\ir.exe? I'm guessing 
no. I'm NOT saying it should be. I'm saying use the other hosting method 
I told you to. I believe that will use IronRuby's exe.config for 
IronRuby. If you don't want to use my suggestion, then you need to 
modify the relative paths in your app.config to point to the right 
location.

JD
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 20:01
I used the above code that you provided but it is throwing exceptions:

 static void Main(string[] args)
        {
            var setup = ScriptRuntimeSetup.ReadConfiguration();

            var runtime = Ruby.CreateRuntime(setup); // error is thrown 
here
            var engine = Ruby.GetEngine(runtime);

And the exception is:


Unhandled Exception: System.ArgumentException: Invalid argument value
Parameter name: ScriptRuntimeSetup must have at least one LanguageSetup
   at Microsoft.Scripting.Hosting.ScriptRuntimeSetup.ToConfiguration()
   at Microsoft.Scripting.Hosting.ScriptRuntime..ctor(ScriptRuntimeSetup 
setup)
   at IronRuby.Ruby.CreateRuntime(ScriptRuntimeSetup setup)
   at IronRubyConsoleApp.Program.Main(String[] args) in 
C:\Projects\ILoveIronRub
y\ILoveIronRuby\IronRubyConsoleApp\Program.cs:line 16
Press any key to continue . . .


Jim Deville wrote:
> Is app.config in the same directory as c:\path\to\ir.exe? I'm guessing 
> no. I'm NOT saying it should be. I'm saying use the other hosting method 
> I told you to. I believe that will use IronRuby's exe.config for 
> IronRuby. If you don't want to use my suggestion, then you need to 
> modify the relative paths in your app.config to point to the right 
> location.
> 
> JD
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 20:04
My fault I did not include the App.config settings. So, now I have 
copied everything from ir.exe.config into my App.config and I run the 
application and get the following error:


Unhandled Exception: IronRuby.Builtins.LoadError: no such file to load 
-- open-u
ri
   at 
Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame 
fram
e)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame 
frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 
arg0, T1 a
rg1)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope, Boolean 
bindGlobals)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink 
errorSink)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope 
scope)
   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)
   at IronRubyConsoleApp.Program.Main(String[] args) in 
C:\Projects\ILoveIronRub
y\ILoveIronRuby\IronRubyConsoleApp\Program.cs:line 30
Press any key to continue . . .



Mohammad Azam wrote:
> I used the above code that you provided but it is throwing exceptions:
> 
>  static void Main(string[] args)
>         {
>             var setup = ScriptRuntimeSetup.ReadConfiguration();
> 
>             var runtime = Ruby.CreateRuntime(setup); // error is thrown 
> here
>             var engine = Ruby.GetEngine(runtime);
> 
> And the exception is:
> 
> 
> Unhandled Exception: System.ArgumentException: Invalid argument value
> Parameter name: ScriptRuntimeSetup must have at least one LanguageSetup
>    at Microsoft.Scripting.Hosting.ScriptRuntimeSetup.ToConfiguration()
>    at Microsoft.Scripting.Hosting.ScriptRuntime..ctor(ScriptRuntimeSetup 
> setup)
>    at IronRuby.Ruby.CreateRuntime(ScriptRuntimeSetup setup)
>    at IronRubyConsoleApp.Program.Main(String[] args) in 
> C:\Projects\ILoveIronRub
> y\ILoveIronRuby\IronRubyConsoleApp\Program.cs:line 16
> Press any key to continue . . .
> 
> 
> Jim Deville wrote:
>> Is app.config in the same directory as c:\path\to\ir.exe? I'm guessing 
>> no. I'm NOT saying it should be. I'm saying use the other hosting method 
>> I told you to. I believe that will use IronRuby's exe.config for 
>> IronRuby. If you don't want to use my suggestion, then you need to 
>> modify the relative paths in your app.config to point to the right 
>> location.
>> 
>> JD
Posted by Ivan Porto Carrero (Guest)
on 2010-03-01 20:26
(Received via mailing list)
Did you change the paths in the app.config file to be absolute?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Microsoft IronRuby/C# MVP
Posted by Mohammad Azam (azamsharp)
on 2010-03-01 20:28
Ahh I did not do that!! I think I will just use path collection and 
List<String> this is just too much work.

Ivan Porto Carrero wrote:
> Did you change the paths in the app.config file to be absolute?
> 
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
> Microsoft IronRuby/C# MVP
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.