creating an order

Hi 

I am trying to create an order using C# but I get an error with the "invoke" as below

 An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Exception has been thrown by the target of an invocation.

This is how I am trying to create the order. Am I missing something?

using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))
{
pvx.InvokeMethod("Init", @"C:\Sage\Sage 100 Advanced\MAS90\Home");
using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")))
{
int TaskID = (int)oSS.InvokeMethod("nLookupTask", "SO_SalesOrder_ui");
oSS.InvokeMethod("nSetProgram", TaskID);
using (DispatchObject ordeR = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", oSS.GetObject())))
{

object[] getNextOrd = new object[] { "" };
ordeR.InvokeMethodByRef("nGetNextSalesOrderNo", getNextOrd);

ordeR.InvokeMethod("nSetKey", getNextOrd);


ordeR.InvokeMethod("nSetValue", "CustomerNo$", "TST");
ordeR.InvokeMethod("nSetValue", "PrintSalesOrders$", "N");
ordeR.InvokeMethod("nSetValue", "PrintPickingSheets$", "N");
ordeR.InvokeMethod("nSetValue", "TaxSchedule$", "NONTAX");
ordeR.InvokeMethod("nSetValue", "SalespersonNo$", "TEST");
ordeR.InvokeMethod("nSetValue", "TermsCode$", "00");
ordeR.InvokeMethod("nSetValue", "SplitCommissions$", "N");


using (DispatchObject soLine = new DispatchObject(ordeR.GetProperty("oLines")))
{
soLine.InvokeMethod("nAddLine");
soLine.InvokeMethod("nSetValue", "ItemCode$", "TST CODE");
soLine.InvokeMethod("nSetValue", "QuantityOrdered", "10");
soLine.InvokeMethod("nWrite");

ordeR.InvokeMethod("nWrite");
}

}
}
}