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:
'abc'
, are you sure you are loading the correct version of the Ruby code? – Albin Sunnanbo Mar 18 '11 at 12:32