简体   繁体   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#

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.我对 Sage 50 SDK 非常陌生,当我尝试运行示例 c# 代码示例时,我收到以下错误消息。

'Save failed: Unable to cast COM object of type 'System.__ComObject' to interface type 'Interop.PeachwServer.Application'. “保存失败:无法将类型为“System.__ComObject”的 COM 对象转换为接口类型“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)).'此操作失败,因为 IID 为“{3545AEE8-388A-41CE-802C-6B9272BB1D54}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)) .'

The following is the code from the program.cs file.以下是 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();

           
        }

    }
}

Can anyone assist me in figuring out what this error means and how it can be resolved?任何人都可以帮助我弄清楚这个错误意味着什么以及如何解决它? Thank you.谢谢你。

I had the same issue.我遇到过同样的问题。 It was after I updated Sage to 2021.1.1.是在我将 Sage 更新到 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.示例代码引用了与最新版本的 Sage 不兼容的 Interop.PeachwServer 版本 27.0.0.0。

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

暂无
暂无

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

相关问题 :'无法将类型为'System .__ ComObject'的COM对象转换为接口类型 - : 'Unable to cast COM object of type 'System.__ComObject' to interface type 在C#中加载COM对象抛出异常“无法将类型为'System .__ ComObject'的COM对象转换为接口类型...”,但C ++或VB没有 - Loading COM object in C# throws exception “Unable to cast COM object of type 'System.__ComObject' to interface type …”, but C++ or VB not 无法使用 STAThread 属性转换类型为“System.__ComObject”的 COM 对象 - Unable to cast COM object of type 'System.__ComObject' with STAThread attribute 无法将类型'System .__ ComObject'的COM对象转换为IRTDUpdateEvent的接口类型 - Unable to cast COM object of type 'System.__ComObject' to interface type for IRTDUpdateEvent 无法转换类型为'System .__ ComObject'的COM对象 - Unable to cast COM object of type 'System.__ComObject' 无法转换'System .__ ComObject类型的COM对象 - Unable to cast COM object of type 'System.__ComObject SAP:无法将“System.__ComObject”类型的 COM 对象转换为接口类型“sapfewse.GuiTextField” - SAP: Unable to cast COM object of type 'System.__ComObject' to interface type 'sapfewse.GuiTextField' C# outlook: Unable to cast COM object of type 'System._ComObject' to Interface type 'Microsoft.Office.Interop.Outlook.MailItem.' - C# outlook : Unable to cast COM object of type 'System._ComObject' to Interface type 'Microsoft.Office.Interop.Outlook.MailItem.' System.InvalidCastException:无法将类型为“System .__ ComObject”的COM对象强制转换为接口类型“System.Collections.IEnumerable” - System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable' 获取 CLR 对象属性引发无法转换类型为“System.__ComObject”的 COM 对象 - Getting CLR object property raises Unable to cast COM object of type 'System.__ComObject'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM