I am getting an error when I try to create a new customer in Quickbooks Desktop.
The error:
Object reference not set to an instance of an object.
The error occurs when I try to create the address for the customer.
Customer qbdCustomer = new Customer();
qbdCustomer.Name = txtCompany.Text;
qbdCustomer.GivenName = txtFName.Text;
qbdCustomer.FamilyName = txtLName.Text;
qbdCustomer.Address[0].Line1 = txtAddress.Text;
qbdCustomer.Address[0].Line2 = txtAddress2.Text;
qbdCustomer.Address[0].City = txtCity.Text;
qbdCustomer.Address[0].CountrySubDivisionCode = drpState.SelectedItem.Value;
qbdCustomer.Address[0].PostalCode = txtZip.Text;
qbdCustomer.Phone[0].FreeFormNumber = txtPhone.Text;
qbdCustomer.Email[0].Address = txtEmail.Text;
Customer customerAdded = (new DataServices(context)).Add(qbdCustomer);
Like I said the error occurs when it gets to the first address line. The Name, GivenName, and FamilyName fields work so it has to be something to do with the array for the address.
I have been stuck on this for a couple days, any help would be greatly appreciated.
Create a PhysicalAddress object and assign it back to the Customer Address property:
The same applies to the Phone and Email properties.