0

我对 Sage 50 SDK 非常陌生,当我尝试运行示例 c# 代码示例时,我收到以下错误消息。

“保存失败:无法将“System.__ComObject”类型的 COM 对象转换为接口类型“Interop.PeachwServer.Application”。此操作失败,因为 IID 为“{3545AEE8-388A-41CE-802C-6B9272BB1D54}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE)) 。

以下是 program.cs 文件中的代码。

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();

           
        }

    }
}

谁能帮助我弄清楚这个错误的含义以及如何解决它?谢谢你。

4

1 回答 1

0

我遇到过同样的问题。那是在我将 Sage 更新到 2021.1.1 之后。

示例代码引用了与最新版本的 Sage 不兼容的 Interop.PeachwServer 版本 27.0.0.0。

我通过将示例项目中的引用替换为 V.28.0.0.0 并重建项目来解决它,您应该能够在此处找到最新版本的 Interop.PeachwServer:C:\Program Files (x86)\Sage\Peachtree

于 2020-11-13T17:11:48.587 回答