# ScriptRunner RunFunction throws exception when incorrect number of arguments are passed

**URL:** https://forum.alternetsoft.com/t/scriptrunner-runfunction-throws-exception-when-incorrect-number-of-arguments-are-passed/369
**Category:** AlterNET Studio Support
**Tags:** scripter
**Created:** [February 10, 2023, 12:49am UTC](https://forum.alternetsoft.com/t/scriptrunner-runfunction-throws-exception-when-incorrect-number-of-arguments-are-passed/369 "2023-02-10T00:49:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![andrew.phillips](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/a/606060/32.png) [@andrew.phillips](https://forum.alternetsoft.com/u/andrew.phillips)
#### Post date: [February 10, 2023, 12:49am UTC](https://forum.alternetsoft.com/t/scriptrunner-runfunction-throws-exception-when-incorrect-number-of-arguments-are-passed/369/1 "2023-02-10T00:49:24Z")

</div>

I am attempting to run a javascript function using the **ScriptRunner** class and get an exception if the number of arguments passed in as the second parameter of the **RunFunction** does not match the number of arguments expected in the javascript function I am attempting to execute. Is there a way for the **ScriptRunner** class to determine how many parameters the javascript function expects before the **RunFunction** procedure is called?

For instance I want to be able to do something like this:

ScriptRunner scriptRunner;

// Set up scriptRunner object

int num\_of\_parameters = scriptRunner.GetFunctionParametersCount(“Main”);

if(calculationArgsObjectList.Count == num\_of\_parameters)  
{  
scriptRunner.RunFunction(“Main”, calculationArgsObjectList.ToArray());  
}  
else  
{  
// Log error that an an incorrect number of arguments have been supplied to the “Main” function.  
}

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [February 15, 2023, 6:55am UTC](https://forum.alternetsoft.com/t/scriptrunner-runfunction-throws-exception-when-incorrect-number-of-arguments-are-passed/369/2 "2023-02-15T06:55:17Z")

</div>

Hi Andrew,

Sorry for the late reply,

We looked at this problem, and it looks like with some small modifications of our TypeScript/JavaScript Scripter we can add a method to evaluate an expression within already parsed code, so you will be able to use javascript-like expression to evaluate number of parameters for a given function like this:

var argLen = scriptRun.ScriptHost.Evaluate(“Main.length”);

We will try to push an update to NuGet packages with this functionality shortly.

Kind regards,  
Dmitry

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [March 7, 2023, 5:25am UTC](https://forum.alternetsoft.com/t/scriptrunner-runfunction-throws-exception-when-incorrect-number-of-arguments-are-passed/369/3 "2023-03-07T05:25:54Z")

</div>

Hi Andrew,

We have just published a new version(8.1.10) to NuGet, which now supports JavaScript expression evaluation, which you can use to obtain a number of parameters before calling the function.

Kind regards,  
Dmitry
