Finding out which line is causing "Index out of range"?

I’m working on a very large grasshopper project for my architecture masters thesis, and using a lot of custom c# components, many nested lists, and lots of RNG for procedural generation. I keep running into problems in which something in my code goes wrong (all sorts of different causes), and I get:

“error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index (line: 0)”

Now, I’m well aware of what this means, that something in my code is trying to call an index in one of my lists or arrays that does not exist. However, since the error doesn’t specify which line is causing the invalid index call, it can be INCREDIBLY time consuming to debug. Often just commenting out lines of code until I find the culprit is not enough, as it occurs within a function called from within a particular iteration of a loop. At times I have to spend hours adding in extra print lines and measures to end the module run early in order to find out what is causing it.

So my question is, is there any way I can get more detailed error information, including what line caused the error, and which line the function containing the line causing the error may have been called from? I’ve worked in programs before which have done this, such as Unity 3D, is this kind of more detailed error completely unavailable in Grasshopper, or is there some way to get more detailed error readouts? Any help would be greatly appreciated.

Use Visual Studio :grinning:

Yup, use VS the GH C# components don’t have a proper IDE making writing 200+ lines of code unmaintainable, unproductive and pointless. You also don’t have access to a debugger. If you want to write serious code move to an IDE. VS is very good.

Well, thanks very much for your input. Unfortunately, I’ve put far too much time into the project in grasshopper already, and I’m too close to my deadline to warrant learning VS and rewriting the whole thing there. However, I’ll definitely keep this in consideration if I ever end up doing another parametric design project on this scale.

I’m an absolute fool and didn’t realize you were talking about developing GH components in VS, instead of remaking my entire project from scratch in VS. Anyways I’m learning to make modules in VS now and this should save me a lot of time. Thanks!

1 Like