Home › Forums › CoreObjX / DB › Specified cast is not valid.
This topic contains 3 replies, has 2 voices, and was last updated by admin28 11 months ago.
Trying to create a new customer using the following code from CoreObjX Customers Documentation:
qbcustomer = conn.Company.Customers.Add(customer.FirstName);
I immediately get the error message ‘Specified cast is not valid.’. customer.FirstName is a string. It gives me the same error if I just hardcode a string value “New customer name”.
Please provide some feedback as to why this might be happening, thanks.
This is vb.net sample:
You will need to create a new reference to the connection
Dim qb As New CoreObjX80.QBConnection()
Create an object:
Dim mCust As CoreObjX70.Customer
Assign value to the customer’s fields:
qb.Company.Customers.Rename(mCust, txtName.Text) //this will create a full name which is the only
//required field to add a customer
mCust.CompanyName = txtCompanyName.Text
mCust.FirstName = txtfirstName.Text
mCust.LastName = txtlastName.Text
mCust.Phone = txtPhone.Text
mCust.BillTo.Line1 = txtBillto1.Text
mCust.BillTo.Line2 = txtBillto2.Text
mCust.BillTo.City = txtBilltoCity.Text
mCust.BillTo.State = txtBilltoState.Text
mCust.BillTo.PostalCode = txtBilltoZip.Text
mCust.Email = txtEmail.Text
Finally: commit the new customer:
Dim oErr As CoreObjX70.qcError
Dim s As String
If mCust Is Nothing Then Exit Sub
On Error GoTo erh
AddCust()
qb.Company.Customers.Commit(mCust)
MsgBox(mCust.Name & ” added successfully.”)
Exit Sub
erh:
For Each oErr In mCust.Errors
s = s & oErr.Description & vbCrLf
Next
MsgBox(Err.Description & vbCrLf & s)
Yudel, thank you for the reply!
However, I was already aware of that vb example, and unfortunately it doesn’t help in my case.
As I said in the OP, I am using the documentation provided here (https://help.synergration.com/latest/coreobjx/customers) for c#.
The initial Add() is not taking a string passed to it. I can’t set the FirstName property directly because it is readonly.
qbcustomer.FullName = “This won’t work!”;
It seems the only way to create a new customer is using Add():
qb.Company.Customers.Add(“This should work, but it isn’t!”);
Is it possible to get one of the developers to comment?
Edit:
I don’t know if it helps, but here is something I tried:
CoreObjX80.Customer qbcustomer = new CoreObjX80.Customer(); ==> Results in this error message:
“Retrieving the COM class factory for component with CLSID {915B0130-FEAE-4DCF-94D5-D066092626C1} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)).”
My project targets x86 already, so that isn’t the issue.
Is something wrong with my install?
Ok, so I uninstalled all Synergration applications on my development box… OpenSync, CoreObjX80 / CoreObjXDB80. Rebooted, and installed just OpenSync 3.0.28 and used the CoreObjX80.dll from that installation.
I believe I have gotten past the above issue. Of course, as seems to be the case using this library, I’m having a new issue…. but I’m working through it so far with the help of this post: https://synergration.com/forums/topic/error-on-commit/
You must be logged in to reply to this topic.