[英]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.