As implied in my last post, I’ve been involved in developing some JScripts recently. Infact, nearly half a dozen scripts that are fairly large. In these scripts I created classes to handle data, and in some instances these scripts would return an array of these objects.

Infact, one of these scripts returned an array of these through three different methods like so

privatefunctionreturnAnArray() : PotatoItTestClass[]

– this created an issue if I returned null. I’m sure that if you’ve read the JScript specification from start to end you’d already know this but I didn’t 🙂

Consider this piece of code. I have a called call PotatoITTestClass, I have a function which returns an array of these objects.

Then we end up getting an error “Error: Unable to cast object of type ‘System.DBNull’ to type ‘MForms.JScript.PotatoItTestClass[]’.” – not very kewl at all. I’ve done this sort of thing heaps of times in C# even done it in VB.Net without issue but in JScript…well…

Thankfully the solution to the issue is pretty straight forward, we don’t specify the type that holds the results or the type of the method