繁体   English   中英

无法将类型为“System.__ComObject”的 COM 对象转换为接口类型“Interop.PeachwServer.Application” - Sage SDK 2018 CreateCustomerDemo c#

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

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

           
        }

    }
}

任何人都可以帮助我弄清楚这个错误意味着什么以及如何解决它? 谢谢你。

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

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

我通过将示例项目中的引用替换为 V.28.0.0.0 并重建项目解决了这个问题,您应该可以在这里找到最新版本的 Interop.PeachwServer:C:\\Program Files (x86)\\Sage\\Peachtree

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM