Hi
I am getting below error on above line -
SAPbouiCOM.Application oApplication = new SAPbouiCOM.Application();
int connectionResult = oCompany.Connect();
if (connectionResult != 0)
{
throw new Exception("Error connecting to SAP Business One: " + oCompany.GetLastErrorDescription());
}
SboGuiApi sboGuiApi = new SboGuiApi();
oApplication = sboGuiApi.GetApplication();
Thanks
Ramco RamcoPosted Feb 12, 2025, 6:11 AM
Hi Jayraj
I am making connection like this . How i can assign value to oApplication
I am able to connect. Now further what code i should write
Thanks
Jayraj ChhayaPosted Feb 12, 2025, 6:06 AM
Hello Ramco,
The error you are encountering, "Specified cast is not valid," suggests that the object you are trying to cast does not match the expected type. In your code, the issue likely arises from the line where you attempt to assign
oApplicationusingsboGuiApi.GetApplication().To resolve this, ensure that the
SboGuiApiis correctly initialized and that the application is running in the expected context. Here’s a refined approach:Additionally, verify that your project references the correct SAP Business One SDK assemblies. If the issue persists, consider checking the compatibility of the SDK version with your application. Proper initialization and type checks can help prevent this casting error.