# Ruby Instance of C# Class Isn't Really the C# Class

**URL:** <https://www.ruby-forum.com/t/ruby-instance-of-c-class-isnt-really-the-c-class/236550>\
**Category:** IronRuby\
**Created:** [September 13, 2013, 8:59pm UTC](https://www.ruby-forum.com/t/ruby-instance-of-c-class-isnt-really-the-c-class/236550 "2013-09-13T20:59:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [September 13, 2013, 8:59pm UTC](https://www.ruby-forum.com/t/ruby-instance-of-c-class-isnt-really-the-c-class/236550/1 "2013-09-13T20:59:30Z")

</div>

Hi,

I have a class defined in C# which I’m creating in Ruby and returning;  
then  
C# adds it to an array. It’s simple (honest).

My setup is simple: the main project, and a class library called  
“SharedClasses.” Here’s a class:

public class SimpleItem  
{  
public string Name { get; set; }  
public int Value { get; set; }

```
    public SimpleItem(string name, int value)
    {
        this.Name = name;
        this.Value = value;
    }
}

```

Okay, nothing special here. Now, in Ruby, here’s the script I want to  
run:

require ‘SharedClasses.dll’  
include SharedClasses  
SimpleItem.new(“Red Gem”, 100);

What I want to achieve, is to return the instance created back to C#,  
and  
add it to a List.

I can’t do it. Currently, I get an InvalidOperationException: “can’t  
convert SharedClasses::SimpleItem into SharedClasses::SimpleItem”

Here’s the code I use to create the Ruby instance:

var engine = Ruby.CreateEngine();  
var newItem = engine.Execute(ruby);

I posted a Stack Overflow question for a more complex version of this  
problem (this is the simplest case I could distill). Under other  
circumstances, I can see that the two instances are the same, except  
their  
context (one is Default and one is LoadNeither).

Full post is here:

> <https://stackoverflow.com/questions/18774700/cant-convert-xyz-to-xyz-in-ironruby>

What am I doing wrong?

–Ashiq

P.S. Visual Studio 2012 solution zip file, including IronRuby 1.13 via  
NuGet, is available here: [http://temp-share.com/show/KdP0s538h](http://temp-share.com/show/KdP0s538h)

---

<div class="post-metadata">

**Author:** ![ashes999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@ashes999](https://www.ruby-forum.com/u/ashes999)\
**Post date:** [September 13, 2013, 10:41pm UTC](https://www.ruby-forum.com/t/ruby-instance-of-c-class-isnt-really-the-c-class/236550/2 "2013-09-13T22:41:43Z")

</div>

Hi Ashiq,

I remember running into something similar, I think I needed to use:

load\_assembly ‘SharedClasses.dll’

---

<div class="post-metadata">

**Author:** ![ashes999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@ashes999](https://www.ruby-forum.com/u/ashes999)\
**Post date:** [September 13, 2013, 11:02pm UTC](https://www.ruby-forum.com/t/ruby-instance-of-c-class-isnt-really-the-c-class/236550/3 "2013-09-13T23:02:11Z")

</div>

Hi Brandon,

Thanks, it works like a charm. I would love to know why, though 🙂

The working syntax was actually without the .dll extension:  
load\_assembly  
‘SharedClasses’

If you’re on Stack Overflow, feel free to reply to my answer (so you can  
get the rep for it). If not, I will reply myself, so that it’s forever  
documented.

Cheers,

–Ashiq
