Reputation: 91
I using C# DLL ServiceStack.redis in IronRuby. Form Designer was SharpDevelop. the code is:
require 'redis/ServiceStack.Redis' # redis is subfolder in project
...
def Button1Click(sender, e)
object = ServiceStack::Redis.PooledRedisClientManager.new
end
and the error message was:
System.MissingMethodException: undefined method `PooledRedisClientManager' for ServiceStack::Redis:Module
but in dotPeek, I can see the C# code was:
namespace ServiceStack.Redis
{
public class PooledRedisClientManager
{
...
public PooledRedisClientManager()
: this("localhost")
{
}
}
}
How can I import the C# DLL and use in IronRuby ?
Upvotes: 2
Views: 100
Reputation: 91
OK the problem solved.
the keywords are: require path, name change.
I tried to make a C# DLL file look like:
namespace testdll
{
public class MyClass
{
public MyClass()
{
Console.Writeln("run test dll");
}
}
}
and the DLL name was: testdll.dll in IronRuby project, the code I wrote:
require "testdll"
obj = testdll::MyClass.new
that was failed. because Module name of Ruby's first letter must be capitalized.
so I modified the testdll namespace to:
namespace TestDll
then the code in IR was:
obj = TestDll::MyClass.new
it's past.
then I think maybe ServiceStack.Redis was a "wrong" Module name ? so I tried:
namespace Test.Dll # in C#
...
obj = Test.Dll::MyClass.new
failed. at that time I thought that I need to Wrap the ServiceStack.Redis to something like:
namespace Wrap
{
public class Redis : ServiceStack.Redis.SomeClass ...
}
but it's too complicated to be done and I view the original code in IR, and I found the code:
require "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
require "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
and we can use : System::Drawing::Point ... so I view the System.Drawing DLL in dotPeek, I found the code familiar just like ServiceStack.xxx
namespace System.Drawing
so if we can use the code System::Drawing with namespace System.Drawing, why my code will fail ? I tried changed require code from:
require "redis/ServiceStack.redis" to
require "ServiceStack.redis"
then:
object = ServiceStack::Redis::PooledRedisClientManager.new
.... Past ! important things are:
Upvotes: 1