[Ironruby-core] Ruby Instance of C# Class Isn't Really the C# Class

Brandon Doot brandon.doot at gmail.com
Fri Sep 13 20:18:08 UTC 2013


Hi Ashiq,

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

load_assembly 'SharedClasses.dll'




On Fri, Sep 13, 2013 at 2:58 PM, Ashiq A. <alibhai.ashiq at gmail.com> wrote:

> 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<SimpleItem>.
>
> 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<SimpleItem>(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:
> http://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
>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>


-- 
Brandon Doot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20130913/f987c468/attachment.html>


More information about the Ironruby-core mailing list