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

    I couldn't get the local copy to work. "SY_Session" kept failing. I had to point to the server instance of MAS 200. I also ended up Adding a VB Class Library to my project and using VB examples. That got me all the way through Lab 2. There is a typo in Lab 3 if you look at my post from yesterday.

  • 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 John1966

    Greetings,

    Are you running this in a Sage 100 Advanced or Premium (Client Server) installation?  If so, you need to run your code on the server not the workstation or point to the server.  Alternately, you can use DCOM.

    Thank you,

    Kent

  • 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

  • 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