Open-Uri Path in App.Config

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.

I guess you’re talking about that:


Shay.

Shay F. | .NET Technologies Expert | Author of IronRuby Unleashed
|
Sela Technology Center
Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay

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 . . .

Is this still an issue?

Provide a config file like this:

<?xml version='1.0' encoding='UTF-8'?>

<microsoft.scripting>



<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’/>

</microsoft.scripting>

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 paths) to
replace the load paths at run-time

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 C. - 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

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 C. 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 C. - 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

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:


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
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

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 D. 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

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 C. 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:


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
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

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

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

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);

    }

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

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 D. 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);

    }

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 D. 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

Did you change the paths in the app.config file to be absolute?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
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

Ahh I did not do that!! I think I will just use path collection and
List this is just too much work.

Ivan Porto C. wrote:

Did you change the paths in the app.config file to be absolute?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
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

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 A. 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 D. 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