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

Parents
  • 0

    I think that you want the Init path to be a UNC to the server, right?  I don't think it's supposed to be looking at the home folder on your local machine.

    Example:

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

                   {

                         pvx.InvokeMethod("Init", @"\\srv-masserver\SharedFolder\MAS90\Home");

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

                         {

                         }

                   }

  • 0 in reply to willHyland

    I pointed it to the server and that worked! I'm able to set the session object properly, and what I want to do is create a new sales order, and it's breaking now on this line:

    using ( var soHeader = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_SalesOrder_Bus", oSS)))

    I'm getting a NewObject error 95 on that line. Am I missing something here?

  • 0 in reply to jsorge

    I found another thread that pointed me in the right direction about my latest error. I wasn't appending GetObject() to my oSS parameter. Now I'm getting an error 200, but feel like I'm making progress.

  • 0 in reply to jsorge

    Greetings,

    Double check the Set methods used for the Session Object.  Make sure they are correct and that no errors are returned.  If the session object doesn;t have the correct information, then you won't be able to instantiate the business object.  In particular, Make sure you are setting the proper Module and date.  Also, if you have users in Sage 100, use SetUser with the appropriate user and password information instead of Logon.  

    Thanks,

    Kent

  • 0 in reply to Kent Mackall

    Kent,

    Thanks for your helpful replies. I'm setting the user, company, module and date (in that order) and am getting 1 back for each (no error). The user I'm setting has full admin access to the company that I'm using and I've enabled external access on the company. Still I get an error 200, which from my digging around appears to be a general error.

    It feels really close to working, I just need to jump this last hurdle.

    jared

  • 0 in reply to jsorge

    jsorge, are you using a try catch to get that error 200? if so using the oSS.sLastErrorMsg after each step might give you more information. I was getting 200 when the user had no access to the company. Didn't figure it out until I used oSS.sLastErrorMsg

Reply Children
  • 0 in reply to John1966

    Greetings,

    Can you instantiate objects from other Modules?  That would help identify it as a permissions issue of some sort.  What happens if you try a different user or company?

    Thanks,

    Kent

  • 0 in reply to Kent Mackall

    HI Kent,

    I can't get AR_Customer_bus or CI_Item_bus to work either. I'm getting error 200 on both of those as well (same user). I tried with a different user and got the same 200 error as well. Tried with different companies as well.

    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