I'm trying to implement scripting capability to my application. I'm using the code below. Whenever I instantiate a new Api
object, the application is supposed to quit (a little testing thing :p)
However, the application crashes at script.AddObject(...)
with the error Specified cast is not valid.
Is there a step I'm missing here?
public class ApiExposed
{
public string ModuleName;
public void Exit()
{
System.Environment.Exit(0);
}
}
public class Api
{
ScriptControlClass script;
ApiExposed ApiObj;
public Api()
{
ApiObj = new ApiExposed();
script = new ScriptControlClass();
script.Language = "VBScript";
script.AddObject("tbapi", (object)ApiObj, true);
script.Eval("tbapi.Exit()");
}
}