Unable to cast GetPlugInObject("Grasshopper") to GH_RhinoScriptInterface


In the Grasshopper plugin for Tekla, we get Grasshopper from Rhino like this in order to launch it:

var grasshopperInstance = (Grasshopper.Plugin.GH_RhinoScriptInterface)Rhino.RhinoApp.GetPlugInObject("Grasshopper");

(Rhino has been launched using new RhinoCore() if that matters)

This works perfectly in almost all cases. But now one customer is reporting that they get this error message when doing the casting using Rhino 7 SR18:

System.InvalidCastException: Unable to cast COM object of type ‘System.__ComObject’ to class type ‘Grasshopper.Plugin.GH_RhinoScriptInterface’. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

So if I interpret it correctly the object returned from Rhino.RhinoApp.GetPlugInObject("Grasshopper") is a System.__ComObject, but it can’t be converted into a GH_RhinoScriptInterface. We tried calling GetPlugInObject using the GH plugin guid as well, same results. Even more interesting, it works in some cases but not others, depending on when the code runs (it always runs in the Tekla process though). And it only fails for this user.

Any idea what might be causing this?



I’ve got similar problem when using Grasshopper plugin for Tekla.

Does anyone know the solution?

Hi Piotr,

If you’ve recently installed Rhino 8 final the (partial) solution should be here:

Why this has failed for some users in Rhino 7 I’m still not sure.



I’ve uninstalled Rhino 8 (I’m using Rhino 7 anyway) and it worked. Thanks a lot!

1 Like