Re: Returning a CLR type from IronRuby

Paul Cowan <[email protected]> Tue, 3 Mar 2009 09:41:10 +0000
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
Hi,

Thanks Fabian but that has not worked.

I am wondering if this is possible from IronRuby yet.

Paul

2009/3/3 Fabian Schmied <[email protected]>

> > [A]Horn.Core.DSL.Domain.BuildMetaData cannot be cast to
> > [B]Horn.Core.DSL.Domain.BuildMetaData. Type A originates from
> > 'Horn.Core.DSL.Domain, Version=1.0.0.0, Culture=neutral,
> > PublicKeyToken=null' in the context 'LoadNeither' at location
> >
> 'C:\Projects\horn\branches\rubydsl\src\Horn.Dsl.Specificatioin\bin\Debug\Horn.Core.DSL.Domain.dll'.
> > Type B originates from 'Horn.Core.DSL.Domain, Version=1.0.0.0,
> > Culture=neutral, PublicKeyToken=null' in the context 'Default' at
> location
> >
> 'C:\Users\paul.cowan\AppData\Local\Temp\1vt2usw2.rxf\Horn.Dsl.Specificatioin\assembly\dl3\1d5ed945\7c19e429_1a97c901\Horn.Core.DSL.Domain.DLL'.
>
> While you'd probably get better answers at a Ruby-specific site, I'll
> give it a try: The problem seems to be that IronRuby loads the
> Horn.Core.DSL.Domain.dll assembly for a second time (and from a
> different location), so the BuildMetaData type used by your IronRuby
> class is not the same as the one used by the C# class.
>
> Can you try to do the following:
> engine.Runtime.LoadAssembly (typeof (BuildMetaData).Assembly); // or
> similar
>
> at the beginning?
>
> Fabian
>
> On Tue, Mar 3, 2009 at 7:22 AM, Paul Cowan <[email protected]> wrote:
> > Hi,
> >
> > I am trying to return a CLR object from Iron Ruby.
> >
> > I have the following CLR type defined in C#
> > public class BuildMetaData
> > {
> >    public string Description { get; set; }
> > }
> >
> >
> > I have the following IronRuby file:
> >
> > $:.unshift(File.dirname(__FILE__) + '/../bin/Debug')
> > require 'mscorlib'
> > require 'Horn.Core.DSL.Domain'
> >
> > class MetaDataFactory
> >    def return_meta_data()
> >        meta = Horn::Core::DSL::Domain::BuildMetaData.new
> >        meta.Description = "A description of sorts"
> >        meta
> >    end
> > end
> >
> > I have the following test that is failing:
> >
> > [Fact]
> > public void Then_a_build_metadata_object_is_returned()
> > {
> >    var engine = Ruby.CreateEngine();
> >
> >    engine.ExecuteFile("test.rb");
> >
> >    var code = String.Format("{0}.new.method :{1}", "MetaDataFactory",
> > "return_meta_data");
> >
> >    var action = engine.CreateScriptSourceFromString(code).Execute();
> >
> >    var result = (BuildMetaData)engine.Operations.Call(action);
> >
> >    Assert.Equal(result.Description, "A description of sorts");
> > }
> >
> >
> >
> >
> > It fails when trying to cast the object returned from IronRuby.
> >
> > I get the following error message:
> >
> > [A]Horn.Core.DSL.Domain.BuildMetaData cannot be cast to
> > [B]Horn.Core.DSL.Domain.BuildMetaData. Type A originates from
> > 'Horn.Core.DSL.Domain, Version=1.0.0.0, Culture=neutral,
> > PublicKeyToken=null' in the context 'LoadNeither' at location
> >
> 'C:\Projects\horn\branches\rubydsl\src\Horn.Dsl.Specificatioin\bin\Debug\Horn.Core.DSL.Domain.dll'.
> > Type B originates from 'Horn.Core.DSL.Domain, Version=1.0.0.0,
> > Culture=neutral, PublicKeyToken=null' in the context 'Default' at
> location
> >
> 'C:\Users\paul.cowan\AppData\Local\Temp\1vt2usw2.rxf\Horn.Dsl.Specificatioin\assembly\dl3\1d5ed945\7c19e429_1a97c901\Horn.Core.DSL.Domain.DLL'.
> >
> > The only way I can access the members of the BuildMetaData is using
> > reflection.
> >
> > If you look at the error message, both types are in different locations.
> >
> > Is there a way round this yet in Ironruby?
> >
> > Cheers
> >
> > Paul
> >
> > ===================================
> > View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
> >
> >
>
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
>

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives