Casting of Rhino objects in GH 7+

Hi,

I started transitioning some of my v6 scripts to v7 and noticed, that Grasshopper now expects direct casts to GH_* objects. Is this expected behavior?

This used to work in v6, but is broken in v7

        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
            pManager.AddCurveParameter("proposed", "proposed", "", GH_ParamAccess.item);
        }

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve proposed;
            DA.GetData(0, ref proposed);
            
            Point3d start = proposed.PointAtStart;
        }

Is it necessary to now cast all Rhino objects to their GH_* counterparts?

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve proposed;
            DA.GetData(0, ref proposed);

            Point3d start = proposed.Value.PointAtStart;
        }

Is there an article describing similar breaking changes between v6 and v7 which I could get familiar with?

No.

What error do you have that using that fixes it?

In v6.35.21222.17001 everything works fine.
Switching to 7.4.21078.1000 (or lower) results in the following error message:

Invalid cast: Curve » Curve

image

If I explicitly cast to GH_Curve as shown above, everything works fine hence my question whether this is expected behavior.

If it were as you say, the message would be Invalid cast: Curve » GH_Curve.

It seems to be a versioning problem. The input curve is using one version of Rhinocommon and the GH_Curve type needs another version of Rhinocommon. Check that you are referencing the correct version in your plugin and try with a new curve.

Thanks, upgrading to 7.10.21256.17000 fixed the issue. My Rhino had the newest update, but I wanted the plugin to stay below 7.5, which requires .NET 4.8 as opposed to 4.5 required by earlier versions.

Anyway, it seems, that it is a breaking change after all - plugins targeting Rhinocommon 6.* work without issues, while 7.0-7.4 break here.

Hi @Dani_Abalde

this seems the exact problem I am encountering^, which is slightly embarrassing, as I released the plug in yesterday…

how would I check and fix that .Net version problem in VS?

thanks in advance

Ben

@benedict, in the NuGet package manager, make sure, that you are either targeting a 6.X or a 7.5+ version of Rhinocommon

1 Like

Remove Rhinocommon.dll from references and get it back the proper version using NuGet.

1 Like

thank you both