Invalid Cast Brep > Brep

Good morning,
I hope all of you are well and safe.

I’ve found an error in some of my C# components, regarding to cast objects. When I’m in debugging mode through Visual Studio the node understand what it is a brep, however when the component is loaded, straight to Rhino GH I got the cast error: Invalid cast: Brep > Brep. (image)
I also got the same error cast points.

This problem doesn’t happen all the time.

I think this problem is related with some VS config that I have? any clue would be very much apreciated.

I’m using Visual studio 2019 community
VS Rhino templates for Rhino 6
Rhino 6

Thanks in advance
Carlos.

Hi Carlos, how about some code? :wink:

Are you creating a local copy of the Rhinocommon.dll within your bin folder?

1 Like

Thanks for your answer, nothing special Nicholas,

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
    pManager.AddBrepParameter("Bowl", "bowl", "The bowl brep geometry", GH_ParamAccess.item);
    pManager.AddCurveParameter("Cutting Curves", "cutCrvs", "Closed Curves to cut the bowl", GH_ParamAccess.list);
}

and:

protected override void SolveInstance(IGH_DataAccess DA)
{
            List<Curve> vomiProj = new List<Curve>();
            Brep bowl = new Brep();

            if (!DA.GetData(0, ref bowl)) { return; }
            if (!DA.GetDataList(1, vomiProj)) { return; }
...

Make sense?
thanks in advance
Carlos.

Thanks TomTom,
I have this in my bin Folder:

it make sense?

Thanks again
Carlos.

I normally have my RhinoCommon as set to do not copy.
May I ask what your output is?
Since it is running through the script fine. you might want to check if there is an error in the SetData, whether a bad brep is being passed possibly or an empty brep?

1 Like

You don’t want to have RhinoCommon in that directory. Make sure that reference is set to copy local = false

3 Likes

yep, my formulation should have indicating that this may be the cause. Such cast errors are often the result of duplicate references.

1 Like

Yup, as others have said that is probably the problem. You should always have all GH dll’s and the RhinoCommon dll with set local copy to false. If not there will be some confusion of which dll to load at runtime,(because there will be multiple copies in your PC) by CLR and things can go crazy. Once you set their local copy false property to false in VS, clean the solution and rebuild the project.

1 Like