Unable to cast COM object of type 'System.__ComObject' to interface type 'Interop.PeachwServer.Application' - Sage SDK 2018 CreateCustomerDemo c#

0

I'm very new to Sage 50 SDK and when I try to run the sample c# code sample, I get the following error message.

'Save failed: Unable to cast COM object of type 'System.__ComObject' to interface type 'Interop.PeachwServer.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3545AEE8-388A-41CE-802C-6B9272BB1D54}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'

The following is the code from the program.cs file.

using System;
using Sage.Sage50.ManagedCOM;
using Sage.Sage50.ManagedCOM.BusinessObjects;
using Sage.Sage50.ManagedCOM.BusinessObjects.Collections;
using Sage.Sage50.ManagedCOM.TransactionObjects;
using Sage.Sage50.ManagedCOM.TransactionObjects.Collections;
using Interop.PeachwServer;

namespace CreateCustomerDemo
{
    class Program
    {

        private static string _applicationUserName = "Peachtree Software";
        private static string _applicationPassword = "9E5643PCU118X6C";
        private static BOCustomerSettings _boCustomerSettings = new BOCustomerSettings(_applicationUserName, _applicationPassword);

        static void Main(string[] args)
        {
            try
            {
                // Gather information about the new customer we are to save

                BOCustomer customer = new BOCustomer();
                Console.WriteLine("What is the new customer's ID?");
                customer.CustomerID = Console.ReadLine();
                Console.WriteLine("What is the new customer's name?");            
                customer.CustomerName = Console.ReadLine();

                BOCustomerCollection customersToSave = new BOCustomerCollection();
                
                customersToSave.Add(customer);

                // Save the customer into the open company
                BOCustomer.SaveAll(_boCustomerSettings, null, customersToSave);
               
                Console.WriteLine("New customer " + customer.CustomerID + " successfully saved.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Save failed: " + ex.Message);
            }

            Console.WriteLine(Environment.NewLine + "Press any key to end this demo.");
            Console.ReadKey();

           
        }

    }
}

Can anyone assist me in figuring out what this error means and how it can be resolved? Thank you.

c#
api
sdk
sage-erp
sage50
asked on Stack Overflow Nov 13, 2020 by Shekinah Budhai • edited Nov 15, 2020 by Samuel Lelièvre

1 Answer

0

I had the same issue. It was after I updated Sage to 2021.1.1.

The sample code has a reference to Interop.PeachwServer Version 27.0.0.0 which is not compatible with the latest version of Sage.

I solved it by replacing the reference in the sample project to V. 28.0.0.0 and rebuild the project, you should be able to find the latest version of Interop.PeachwServer here: C:\Program Files (x86)\Sage\Peachtree

answered on Stack Overflow Nov 13, 2020 by Macarena

User contributions licensed under CC BY-SA 3.0