var t = Type.GetTypeFromProgID("Rhino.Interface");
dynamic com = Activator.CreateInstance(t); // Works, launches Rhino
var rhino = (IRhinoInterface)com; // InvalidCastException
I’m able to launch Rhino fine. But I can’t figure out how to use the returned COM object to actually do anything. If I try to cast it to any of the types in the provided .tlb, I get an InvalidCastException: “Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Rhino.IRhinoInterface’”. If I leave it as dynamic and try to use properties/methods directly (e.g. the ones in samples from Rhino 6 COM Interface and Fail to get IRhinoApplication from COM Object in Rhino 6), I get RuntimeBinderExceptions with messages like "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘‘System.__ComObject’ does not contain a definition for ‘GetScriptObject’’.
Sorry, my bad - I did not read to the end when I saw you trying to use Rhino.Interface. I’ve checked our codebase and when you say
I get RuntimeBinderExceptions with messages like "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘‘System.__ComObject’ does not contain a definition for ‘GetScriptObject’’.
we find the same problem, which is that GetScriptObject is not COM-enabled. If you try other methods, like RunScript or GetPluginObject, those should work, in combination with "Rhino.Application" as prog-id and leaving it as a dynamic type.
Neither of those combinations work, I have the same problem. As I said, I have this problem for every pair of methods/ProgIds I found in any of the linked examples. I was just using Rhino.Interface/GetScriptObject as an example.
Here is some specific code with the same problem:
var t = Type.GetTypeFromProgID("Rhino.Application");
dyamic com = Activator.CreateInstance(t);
(I don’t know if that’s the right way to use RunScript but there’s no method found at all.)
The sample reference above seems to work here. For COM to work, entries in the Registry must be set correctly. So, you might consider repairing your Rhino installation via Control Panel (Programs and Features), to ensure these settings are correct.