I have tried to access a C# DLL using this approach described here without success:
I have made a COM DLL (RubyToCSharp.dll) with: [assembly: ComVisible(true)] and Register for COM interop (like in the example):
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace ComLib
{
[ComVisible(true)]
public class LogWriter
{
public void WriteLine(string line)
{
using (var log = new StreamWriter(File.OpenWrite(@"c:\log.file")))
{
log.WriteLine(line);
}
}
}
}
I am able to access the DLL using this VB script from c:\Windows\SysWOW64\wscript.exe :
Dim obj
set obj = CreateObject("ComLib.LogWriter")
MsgBox TypeName(obj)
but I am not able to access the DLL using System32\wscript.exe
When I finally try to access from Ruby with the following code:
require 'win32ole'
lib = WIN32OLE.new('ComLib.LogWriter')
This happens :
WIN32OLERuntimeError: failed to create WIN32OLE object from `ComLib.LogWriter'
HRESULT error code:0x80040154 Class not registered
even though the DLL seems to be registered in Windows Registry database.
My setup is: Ruby v. 2.4 64bit version on Win10 PC.
Do someone have a working example how to access a C# DLL using Ruby or have any idea why this example does not work?