Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am instantiating a ruby class and calling an instance method from the ruby class via C# program. I am able to instantiate the class. While debugging i can notice the instance method. But once i call it i am getting the RunTimeBinder exception. To add i have referred all the dll's of DLR. I am working on VS 2010. The below source code is wherein i am getting the exception.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Scripting.Hosting;

namespace ConsoleApplication2
{
  class Program
  {
    static void Main(string[] args)
    {
        RunRubyClassInstatainateMethod();
        Console.ReadLine();
    }

    private static void RunRubyClassInstatainateMethod()
    { 
  /*WHEN PUT A BREAK POINT TO THE BELOW LINE OF CODE I AM ABLE TO SEE 
    THE print_mthd() under Instance Method list*/
        dynamic stretchstring = RubyExampleCode.CreateRubyProduct();
  /*THE BELOW CALL RESULTS IN AN EXCEPTION*/
        stretchstring.print_mthd();
    }
  }
  class RubyExampleCode
  {

    private static dynamic productClass;
    private static ScriptEngine rbEngine;
    private static dynamic loadFile;
    static RubyExampleCode()
    {
        rbEngine = IronRuby.Ruby.CreateEngine();
        loadFile = rbEngine.ExecuteFile("R.rb");
        productClass = rbEngine.Runtime.Globals.GetVariable("RubyProduct");
    }

    public static void invokeDynaMthd()
    {
        loadFile.print_mthd();
    }
    public static dynamic CreateRubyProduct()
    {
        return rbEngine.Operations.CreateInstance(productClass);
    }
  }
}

/***********************************************************************/

/*This is the ruby class definition*/
class RubyProduct
def print_mthd
puts "This is a demo"
end
end

The exception details are:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException was unhandled
  Message='IronRuby.Builtins.RubyObject' does not contain a definition for 'abc'
  Source=Anonymously Hosted DynamicMethods Assembly
  StackTrace:
       at CallSite.Target(Closure , CallSite , Object )
       at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0](CallSite site, T0 arg0)
       at ConsoleApplication2.Program.RunRubyClassInstatainateMethod() in C:\Users\IC012722\documents\visual studio 2010\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 21
       at ConsoleApplication2.Program.Main(String[] args) in C:\Users\IC012722\documents\visual studio 2010\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 13
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
share|improve this question
    
What is the stack trace and the exception type? –  Albin Sunnanbo Mar 18 '11 at 6:21
    
I tried your code on my computer and it worked without a problem. Please add the IronRuby version you're working with and also the exception details. –  Shay Friedman Mar 18 '11 at 7:39
    
@Shay The version of Iron Ruby dll is: Version : 0.9.5.0 Run Time Version : v2.0.50727 –  Sriharsha Mar 18 '11 at 10:07
1  
Is there any reason you are on such an old version of .Net and of IronRuby? Since you are on VS2010, why not use .net 4 with 1.1.3 from ironruby.codeplex.com ? –  Stuart Mar 18 '11 at 11:16
1  
Looks strange that the exception complains about not finding 'abc', are you sure you are loading the correct version of the Ruby code? –  Albin Sunnanbo Mar 18 '11 at 12:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.