# Busy Day with IronRuby

**URL:** <https://www.ruby-forum.com/t/busy-day-with-ironruby/127298>\
**Category:** IronRuby\
**Created:** [January 28, 2008, 12:20am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298 "2008-01-28T00:20:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:20am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/1 "2008-01-28T00:20:16Z")

</div>

OK, so I couldn’t get some of the simple examples of using RubyEngine  
to start calling Ruby from C#…

So I spent a bit reading through the mailing list archives (realizing  
while doing that, that I’d asked a frequently asked question).

Now, I hope I’m not asking another stupid question.

I found another post (  
[http://rubyforge.org/pipermail/ironruby-core/2008-January/000616.html](http://rubyforge.org/pipermail/ironruby-core/2008-January/000616.html)  
) that suggests a method of running Ruby.

However, I get an error on this line

```
        IScriptEngine engine = IronRuby.GetEngine(runtime);

```

Which shows this stack trace

at System.RuntimeMethodHandle.\_InvokeConstructor(Object[] args,  
SignatureStruct& signature, IntPtr declaringType)  
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args,  
SignatureStruct signature, RuntimeTypeHandle declaringType)  
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags  
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,  
Binder binder, Object[] args, CultureInfo culture, Object[]  
activationAttributes)  
at System.Activator.CreateInstance(Type type, BindingFlags  
bindingAttr, Binder binder, Object[] args, CultureInfo culture,  
Object[] activationAttributes)  
at System.Activator.CreateInstance(Type type, Object[] args)  
at Microsoft.Scripting.Utils.ReflectionUtils.CreateInstance[T](Type  
actualType, Object[] args) in  
c:\Libraries\IronRuby\trunk\src\microsoft.scripting\Utils\ReflectionUtils.cs:line  
127

–  
Greg A.  
Software Development Manager  
SSI Services

[http://kc.vanadium.com](http://kc.vanadium.com)  
[http://www.pghcodingdojo.org](http://www.pghcodingdojo.org)  
[http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:26am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/2 "2008-01-28T00:26:43Z")

</div>

hello\_world.rb only contains: puts “Hello, World!!!”

hth  
Ivan

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:23am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/3 "2008-01-28T00:23:47Z")

</div>

Hi Greg,

This is what i used at some point, that should still work atm.

class Program  
{  
static void Main(string[] args)  
{  
//TODO: review this when the hosting api changes.  
IScriptEnvironment runtime =  
ScriptEnvironment.GetEnvironment();

```
        Console.WriteLine("Executing from file:");
        runtime.ExecuteFile("..\\..\\hello_world.rb");

        IScriptEngine engine = IronRuby.GetEngine(runtime);
        IScriptScope scope = engine.CreateScope();

        List<string> strings = new List<string>();
        strings.Add("Hello, ");
        strings.Add("World!!!");
        IronRuby.GetExecutionContext(runtime).GlobalVariables[

```

SymbolTable.StringToId(“strings”)] = strings;

```
        SourceUnit script = engine.CreateScriptSourceFromString(

```

@"  
puts ““Hello World! There are #{$strings.count.to\_s} strings:””  
$strings.each\_with\_index { |s,i| puts “”#{i}: #{s}"" }  
");

```
        Console.WriteLine("Executing from string:");
        engine.Execute(scope, script);
    }
}
```

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:34am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/4 "2008-01-28T00:34:55Z")

</div>

I’m actually getting ready to work on an IronRuby quick start blog  
post, based on my experiences, but this is the simplest “hello world”  
using the hosting mechanism I could come up with:

using System;  
using Ruby.Runtime;  
using Microsoft.Scripting.Hosting;  
namespace RubyExample  
{  
static class Program  
{  
///

#  
/// The main entry point for the application.  
///   
[STAThread]  
static void Main()  
{  
IScriptEnvironment scriptenvironment =  
ScriptEnvironment.GetEnvironment();  
IScriptEngine rubyengine =  
scriptenvironment.GetEngine(“ruby”);  
scriptenvironment.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString(“puts  
‘Hello World!\nPress Any Key To Continue…’”) );  
Console.ReadKey();

```
    }
}

```

}

be sure to add references to Microsof.Scripting.dll and IronRuby.dll  
(and IronRuby.Libraries.dll if you’re so inclined).

You can also use scriptenvironment.ExecuteFile(pathtofile) if you have  
your ruby script inn a standalone file.

On Jan 27, 2008 6:16 PM, Greg A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ) that suggests a method of running Ruby.  
> SignatureStruct signature, RuntimeTypeHandle declaringType)  
> actualType, Object[] args) in  
> [http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
[Polymath Programmer]  
[http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:41am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/5 "2008-01-28T00:41:59Z")

</div>

Thanks to both of you. I’ll try those approaches.

Incidentally, the line which threw my error was in  
Microsoft.Scripting.Hosting.PlatformAdaptationLayer at line 90

#if !SILVERLIGHT  
return Assembly.Load(name); \<== ERROR OCCURRED ON THIS  
LINE while “name” == “IronRuby.Libraries”  
#else  
return Assembly.Load(LookupFullName(name));  
#endif

On Jan 27, 2008 6:34 PM, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> {
> 
> ```
> 
> ‘Hello World!\nPress Any Key To Continue…’") );  
> your ruby script inn a standalone file.
> 
> > at System.RuntimeMethodHandle.\_InvokeConstructor(Object[] args,  
> > Object[] activationAttributes)
> 
> –  
> Michael L.  
> [Polymath Programmer]  
> [http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)

–  
Greg A.  
Software Development Manager  
SSI Services

[http://kc.vanadium.com](http://kc.vanadium.com)  
[http://www.pghcodingdojo.org](http://www.pghcodingdojo.org)  
[http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:51am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/6 "2008-01-28T00:51:58Z")

</div>

Success!!

I think a traumatic experience a few months ago has caused the part of  
my brain which deals with Assembly loading to stop working 😉

Obviously, from reading my message (below) there is a problem loading  
IronRuby.Libraries.

When I glanced back over Michael’s email, I realized that I HAVE to  
reference IronRuby.Libraries.dll

Michael? Are you NOT referencing those?

On Jan 27, 2008 6:41 PM, Greg A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> #endif
> 
> > using System;  
> > static void Main()  
> > }
> > 
> > > to start calling Ruby from C#…  
> > > However, I get an error on this line  
> > > invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  
> > > 127
> > > 
> > > * * *
> > 
> > [http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)  
> > [http://kc.vanadium.com](http://kc.vanadium.com)  
> > [http://www.pghcodingdojo.org](http://www.pghcodingdojo.org)  
> > [http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)

–  
Greg A.  
Software Development Manager  
SSI Services

[http://kc.vanadium.com](http://kc.vanadium.com)  
[http://www.pghcodingdojo.org](http://www.pghcodingdojo.org)  
[http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/7 "2008-01-28T19:11:51Z")

</div>

In case anyone is interested:  
[http://michaeldotnet.blogspot.com/2008/01/ironruby-quick-start.html](http://michaeldotnet.blogspot.com/2008/01/ironruby-quick-start.html)

As far as I know that’s correct as of rev 75. Any mistakes or  
omissions please let me know. (I’m still not sure about that SIGNED  
symbol…)

On Jan 27, 2008 6:34 PM, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> {
> 
> ```
> 
> ‘Hello World!\nPress Any Key To Continue…’") );  
> your ruby script inn a standalone file.
> 
> > at System.RuntimeMethodHandle.\_InvokeConstructor(Object[] args,  
> > Object[] activationAttributes)
> 
> –  
> Michael L.  
> [Polymath Programmer]  
> [http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)

–  
Michael L.  
[Polymath Programmer]  
[http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 12:43am UTC](https://www.ruby-forum.com/t/busy-day-with-ironruby/127298/8 "2008-01-28T00:43:10Z")

</div>

Hi Michael

I think we can work together for that, seen as I will have a bunch of  
samples I’m writing for the book

I haven’t gotten round to putting a website/blog up because most of the  
CMS/blog systems out there don’t do exactly what I want (which is not  
much).  
I want it to be ruby of course.

Email me off list if you like the idea?

Cheers  
Ivan

On Jan 28, 2008 12:34 PM, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
