In my company's web application, we provide administrative users the option of creating their own entry forms, including a rules engine for conditionally showing fields and validating input. For this rules engine, we allow you to specify the formula, we replace some values with runtime data, then we use JScript.NET's eval function to evaluate the formula. The javascript file consists of the following:
class
ScriptExecutor
{
function
Execute(Expression)
{
return
eval(""
+ Expression);
}
}
There are a few additional helper functions in this class that have been omitted for clarity.
We then compile this class using "jsc /out:C:\ScriptExecutor.dll /target:library C:\ScriptExecutor.js" then reference the dll in our main app so we can call the Execute method using:
public
static
object
Evaluate( string
Expression )
{
return
new
ScriptExecutor().Execute( Expression );
}
Most of the time this works quite well and does exactly what we want it to, but after a period of time, it simply stops working, throwing a NullReferenceException with a stack trace of:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.JScript.StackFrame.PushStackFrameForMethod(Object thisob, JSLocalField[] fields, VsaEngine engine)
at ScriptExecutor.Execute(Object Expression)
At that point, it will throw the NullReferenceException regardless of the formula used until we recycle the app pool in IIS. This seems to be something internal to the eval function but I don't know what might be going wrong and because this is a production environment (it works fine in development), we can't just attach the Visual Studio debugger.
Any ideas or help would be appreciated.