Rhino6 Com Interface

Hello,
We try connect our program to rhino6 via COM interface.
“rs = rhino.GetScriptObject();” is not work.

Error message from visual studio:

Unable to cast object of type 'System.DBNull' to type 'RhinoScript.RhinoScript'

sample code:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading;

using Rhino;
using RhinoScript;

namespace rhinoCOM
{
class Program
{
static void Main()
{
RhinoScript.RhinoScript rs = null;

        // Try creating an instance of Rhino
        dynamic rhino = null;
        try
        {
            //string rhinoId = "Rhino.Application";
            string rhinoId = "Rhino.Interface";
            System.Type type = System.Type.GetTypeFromProgID(rhinoId);
            rhino = System.Activator.CreateInstance(type);
        }
        catch
        {
        }

        if (null == rhino)
        {
            Console.WriteLine("Failed to create Rhino application");
            return;
        }

        // Wait until Rhino is initialized before calling into it
        const int bail_milliseconds = 15 * 1000;
        int time_waiting = 0;
        while (0 == rhino.IsInitialized())
        {
            Thread.Sleep(100);
            time_waiting += 100;
            if (time_waiting > bail_milliseconds)
            {
                Console.WriteLine("Rhino initialization failed");
                return;
            }
        }

        //rhino.Visible = 1;

        // get error here
        rs = rhino.GetScriptObject();

        double[] pt_1 = { 0, 0, 0 };
        double[] pt_2 = { 100, 100, 100 };

        rs.AddLine(pt_1, pt_2);
    }
}

}

We try this code in other computer, it works.
I have no idea why some computer get error.

Thanks

The the code that we use is below, and never fails us. If you have problems on one computer, but not on other computers, you may need to re-install Rhino on the problematic machine.

private dynamic _rhino;
public void StartRhino()
{
  // Try creating an instance of Rhino
  try
  {
    const string rhinoId = "Rhino.Application";
    Type type = Type.GetTypeFromProgID(rhinoId);
    _rhino = Activator.CreateInstance(type);

  }
  catch (Exception e)
  {
    Log("Error creating COM instance, {0}", e);
    return;
  }

  if (null == _rhino)
  {
    Log("Failed to create Rhino application");
    return;
  }

  // Wait until Rhino is initialized before calling into it
  const int bailMilliseconds = 15 * 1000;
  int timeWaiting = 0;
  while (0 == _rhino.IsInitialized())
  {
    Thread.Sleep(100);
    timeWaiting += 100;
    if (timeWaiting > bailMilliseconds)
    {
      Console.WriteLine("Rhino initialization timed out: Failed");
      return;
    }
  }
  Logger.Info("RhinoCom Initialisation took {0} ms.", timeWaiting);
  _rhino.Visible = 1;
}

Hi, @menno. Thank you for the reply.
I try this code, it works.
But my code also work until “rhino.Visible”.

I try re-install(uninstall and delete registry keys) and test my code, it works!
I delete registry keys by reference to https://wiki.mcneel.com/rhino/5/uninstall

I dont know why, but it works.

Thanks