Debugging Grasshopper Component while loading Grasshopper

Hi,

@DavidRutten I have an issue with grasshopper plugin loading. The plugin works on some windows computers and on some not, with the same newest rhino installed.

It is not possible to debug the component, since the grasshopper gives error while loading grasshopper below, and wont load the half of components.

I quite sure that is because of some file directory issue, but not sure which line of code is causing that.

Any suggestions how to debug components at the start of Grasshopper would be much appreciated.

The error while loading:

    Object: ComponentDrilling (level 1)
    {
      Exception has been thrown by the target of an invocation.
      TargetInvocationException
    }

    Object: ComponentDrilling (level 2)
    {
      The path is not of a legal form.
      ArgumentException
    }

    Object: ComponentCutting2Polylines (level 1)
    {
      Exception has been thrown by the target of an invocation.
      TargetInvocationException
    }

    Object: ComponentCutting2Polylines (level 2)
    {
      The path is not of a legal form.
      ArgumentException
    }

    Object: ComponentOpenPolyline (level 1)
    {
      Exception has been thrown by the target of an invocation.
      TargetInvocationException
    }

Full code of one class that is causing the issue is here:

using Grasshopper.Kernel;
using System.Drawing;
using System.Drawing.Text;
using System;
using System.Collections.Generic;
using Rhino.Geometry;
using System.Windows.Forms;

namespace IBOIS.Components {
    public class ComponentIBOIS : GH_Component {

        public IBOIS.PreviewObject preview;
        public BoundingBox bbox = Utilities.MakaDimensions.MakaBBox();
        public Rhino.Display.DisplayMaterial m = new Rhino.Display.DisplayMaterial(Color.White);
        public override BoundingBox ClippingBox => bbox;
        public double tolerance = 0.01;

        public List<Line> lines = new List<Line>();
        public List<Polyline> polylines = new List<Polyline>();
        public List<Curve> badCurves = new List<Curve>();
        public string directory;
        public List<string> GCode = new List<string>();
        public string filename = "P1234567";
        public double zero1 = 54;
        public double toolr = 5;
        public double toolID = 57;
        public double Zsec = 350;
        public double XYfeed = 5000;
        public double Zfeed = 1500;
        public double Retreat = 60;
        public double infeed = 2;
        public bool notch = true;

        public Dictionary<int,IBOIS.GCode.ToolParameters> tools = IBOIS.GCode.Tool.ToolsFromAssembly();

        public ComponentIBOIS(string Name, string Nick, string Desc) : base(Name, Nick, Desc, "IBOIS", "CNC") { }

        public ComponentIBOIS(string Name, string Nick, string Desc, string subCategory) : base(Name, Nick, Desc, "IBOIS", subCategory) { }


        public override void DrawViewportWires(IGH_PreviewArgs args) {

            if (this.Hidden || this.Locked ) return;

            //Travelling path
            if (preview.PreviewLines0 != null) {
                args.Display.DrawLines(preview.PreviewLines0, Color.Orange, 2);
                //args.Display.DrawArrows(lines, Color.MediumVioletRed);
            }
            //drilling path
            if (preview.PreviewLines1 != null)
                args.Display.DrawLines(preview.PreviewLines1, Color.Orange, 1);
            //Works only with an angle
            if (preview.PreviewLines2 != null)
                args.Display.DrawLines(preview.PreviewLines2, Color.Black, 3);



            if (preview.PreviewPolyline != null)
                args.Display.DrawPolyline(preview.PreviewPolyline, Color.Orange, 2);

            if (preview.badCurves != null)
        
                foreach (Curve c in preview.badCurves) {
                    args.Display.DrawCurve(c, Color.Red, 5);
                }
               
        }

 

        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) {

            for (int i = 0; i < pManager.ParamCount; i++)
                pManager.HideParameter(i);
        }

        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) {
            for (int i = 0; i < pManager.ParamCount; i++)
                pManager.HideParameter(i);
        }

        protected override void SolveInstance(IGH_DataAccess DA) {


        }

        public override Guid ComponentGuid => new Guid("e6eda5fb-6967-425f-8cee-15eade0f26f1"); 

        //https://stackoverflow.com/questions/439007/extracting-path-from-openfiledialog-path-filename
        //https://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog(v=vs.110).aspx
        //https://discourse.mcneel.com/t/save-file-directory/62784/2
        protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu) {
        
                Menu_AppendItem(menu, "Select Directory with Address...", (_, __) => {

                    SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                    saveFileDialog1.FileName = filename;
                    saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                    saveFileDialog1.FilterIndex = 2;
                    saveFileDialog1.RestoreDirectory = true;

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK) {

                        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog1.FileName)) {
                            int i = 0;
                            foreach (string s in GCode) {
                                if (i == 0) {
                                    sw.WriteLine(System.IO.Path.GetFileName(saveFileDialog1.FileName));
                                } else {
                                    sw.WriteLine(s);
                                }
                                i++;
                            }
                            //GCode
                        }

                        ExpireSolution(true);

                    }

                });

  

            Menu_AppendItem(menu, "Select Directory...", (_, __) => {

                var folderDialog = new FolderBrowserDialog();
                var run = folderDialog.ShowDialog();

                if (run == DialogResult.OK) {
                    directory = folderDialog.SelectedPath;
                    System.IO.File.WriteAllLines(folderDialog.SelectedPath + "/" + filename, GCode);
                    Rhino.RhinoApp.WriteLine(directory);
                    Rhino.RhinoApp.WriteLine((GCode.Count > 0).ToString());
                    ExpireSolution(true);
                }

            });

        }



        protected override System.Drawing.Bitmap Icon {
            get {
                return IBOIS.Components.ComponentIBOIS.GetIcon(this); 
            }
        }


        internal static Bitmap GetIcon(GH_ActiveObject comp) {
            string nickName = comp.NickName;
            Bitmap bitmap = new Bitmap(24, 24);
            using (Graphics graphic = Graphics.FromImage(bitmap)) {
                graphic.TextRenderingHint = TextRenderingHint.AntiAlias;
                graphic.DrawString(nickName, new Font(FontFamily.GenericSansSerif, 6f), Brushes.Black, new RectangleF(-1f, -1f, 26f, 26f));
            }
            return bitmap;
        }




    }
}