C# Invocation Error when getting SY_Session

SOLVED

Hello,

I'm writing my first BOI application using C# and I'm having an exception that's getting hit that I don't know what to do about. I'm using the examples provided in the BOI course (specifically example 2) and have imported the DispatchObject into my file. I can create the pvx object just fine and init with the Home directory path, but when I go to invoke the NewObject method on the pvx object to create the SY_Session, I get an exception. Here's my code:

using ( var pvx = new DispatchObject("ProvideX.Script"))

{

pvx.InvokeMethod("Init", @"C:\Sage\Sage 100 ERP Workstation\MAS90\Home");

using ( DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")))

{...}

}

I'm breaking on the second using statement, that creates the session object. The error specifically is: "Exception has been thrown by the target of an invocation."

I confirm that I get the same error even when running the sample code from the BOI class. I'm on Visual Studio 2013 on Windows 7, if that makes a difference. I hope that someone has run into this and can point me in the right direction. Thanks.

jared

  • 0 in reply to jsorge

    Greetings,

    I know you posted that the user was an Admin and that Allow External Access was selected but check those settings again.  Is the user able to access these modules and tasks in Sage 100? If not, it is an issue with the Roles assigned to the user.

    What happens if you run this code directly on the server, instead of just changing the path?  Does that make a difference?

    Do you have access to another installation of Sage 100 (preferably Standard) where you could test?

    If none of the above helps, can you post back your full code.

    Thanks,

    Kent

  • 0 in reply to Kent Mackall

    Hi Kent,

    I have verified that the user I'm using to login, as well as the external access to the company. I don't have any other installation to test with, just the Premium.

    I tried deploying the code to my server and it's not working there either. What I'm building is a web service so I'm just getting a 500 code back.

    I posted the full source to the class I'm working on (minus my password) here: gist.github.com/.../145c009b07bd8470876c.

    Thanks for your help!

    jared

  • 0 in reply to jsorge

    Greetings,

    try changing these lines:

     var sessionObj = oSS.GetObject();                    

     var salesOrderObj = pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", sessionObj);

    To follow the example and use the DispatchObject (this is one line):

     using (DispatchObject SalesOrderObj = new DispatchObject(pvx.InvokeMethod

     ("NewObject", "SO_SalesOrder_bus", oSS.GetObject())))

    Thanks,

    Kent

  • 0 in reply to Kent Mackall

    Hi Kent,

    That's how I tried it before, so I went and split things out. I just put them all back together so it now reads like you wrote. I'm still getting the 200 error. I also noticed that I had typed the sales order as a var, so I changed that to DispatchObject and that's not fixing it either.

    jared

  • 0 in reply to jsorge
    verified answer

    Here is the sample code I have running:

    using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")) )

    {

    oSS.InvokeMethod("nSetUser", "test", "test");

    oSS.InvokeMethod("nSetCompany", "ABC");

    oSS.InvokeMethod("nSetDate", "S/O", "05312010");

    oSS.InvokeMethod("nSetModule", "S/O");

    // Get the Task ID for the AR_Customer_ui program

    int TaskID = (int) oSS.InvokeMethod("nLookupTask", "SO_SalesOrder_ui");

    oSS.InvokeMethod("nSetProgram", TaskID);

    using (DispatchObject so_order = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", oSS.GetObject())))

    I notice this differs slightly from your code in that the SetDate and SetModule methods are reveresed.  I also do not have return values on the Set methods.  If you change your code to follow this sample, does it correct the issue?

    Thanks,

  • 0 in reply to Kent Mackall

    It works! I wasn't getting the Task ID for the SO_SalesOrder_ui. I'm pretty sure that's what I was missing. I had assumed that I didn't need that part since I'm not doing anything in the UI.

    Better documentation on this stuff would be huge. Thanks so much for all of your help Kent!

    jared

  • 0 in reply to jsorge

    Greetings,

    In the BOI training manual under the section titled Instantiating a Security Object there is information on the logic for obtaining the TaskID which is required.

    Thanks,

    Kent