cancel
Showing results for 
Search instead for 
Did you mean: 

Creating/Adding Address Error - Collection was of a fixed size

Senior Member

Creating/Adding Address Error - Collection was of a fixed size

I'm working in C#, using the latest version of the SDK and am having trouble with addresses. I had made a simple Email, first and last name form and it was working great. Now I've added Address information (line 1, city, state, and zip) and I'm getting the "Collection was of a fixed size" error. Here is the address code that I added:

if (!string.IsNullOrWhiteSpace(tbxAddress.Text) &&
    !string.IsNullOrWhiteSpace(tbxCity.Text) &&
    !string.IsNullOrWhiteSpace(tbxState.Text) &&
    !string.IsNullOrWhiteSpace(tbxZipcode.Text))
{
    Address address;

    if (contact.Addresses == null || contact.Addresses.Count() == 0)
    {
        address = new Address();
    }
    else
    {
        address = contact.Addresses[0];
    }

    address.Line1 = tbxAddress.Text.Trim();
    address.City = tbxCity.Text.Trim();
    address.StateName = tbxState.Text.Trim();
    address.PostalCode = tbxZipcode.Text.Trim();

    if (contact.Addresses.Count() == 0)
    {
        contact.Addresses.Add(address);
    }
    else
    {
        contact.Addresses[0] = address;
    }
}

I used basically the exact same methods as the contact form example in the SDK, is there something I'm doing wrong or something that I missed?

5 REPLIES 5
Solution Provider

Re: Creating/Adding Address Error - Collection was of a fixed size

Yeah, I'm getting that too but I'm using VB. It's very wierd. I'm just going to have to give-up for now and move on. :-( (I'm glad it's not just me though.)

 

Bye for now

Jason.

Advisor

Re: Creating/Adding Address Error - Collection was of a fixed size

Why does it take so long for you guys to answer this? In my case I'm getting the same error only I am trying to add a Contact to a ContactList. You have this type of problem for many (all?) of the object types you define in your wrapper code. Please address this.

Advisor

Re: Creating/Adding Address Error - Collection was of a fixed size

Oops! Meant I'm trying to add a contact to a ResultSet

Senior Member

Re: Creating/Adding Address Error - Collection was of a fixed size

So, I've found a way around this, but it's not the best way. Here's what I did:

if (!string.IsNullOrWhiteSpace(tbxAddress.Text) &&
    !string.IsNullOrWhiteSpace(tbxCity.Text) &&
    !string.IsNullOrWhiteSpace(tbxState.Text) &&
    !string.IsNullOrWhiteSpace(tbxZip.Text))
{
    List<Address> adrList = new List<Address>();
    Address address = new Address();

    address.Line1 = tbxAddress.Text.Trim();
    address.City = tbxCity.Text.Trim();
    address.StateName = tbxState.Text.Trim();
    address.PostalCode = tbxZip.Text.Trim();

    adrList.Add(address);

    contact.Addresses = adrList;
}

 The small issue with this way is that it will overwrite the contact's address labeled "other" rather than add one. I've yet to find a way around that, but one thing at a time.

Honored Contributor

Re: Creating/Adding Address Error - Collection was of a fixed size

Hello,

 

First off I want to offer my apologies for the delay in getting this answered! I've been investigating this issue and it appears that the problem currently is related to the to collection of addresses is typed as a list interface. This causes .NET to serialze the contact's address data as a fixed size collection for the sake of effiiciency which stops you form adding new addresses to the collection. In the case od adding contacts to a ResultSet, this is likely to be the same cause.

 

We are working on some minor updates for the .NET wrapper that will include this change, but you can also change this by making the following change to force the type as a list, so that it will default to a collection of variable size.

 

Line 71 of Components/Contacts/Contact.cs:

Before:

        [DataMember(Name = "addresses")]
        public IList<Address> Addresses { get; set; }

After:

        [DataMember(Name = "addresses")]
        public List<Address> Addresses { get; set; }

 

As for the ResultSet issue with adding contacts, I believe that would be the expected behavior, as the ResultSet is intended as a method for parsing data returned from the API, rather than as a structure for long-term storage and manipulation of contact data.

 

If you have any questions, please let us know!

 

Sincerely,

 

Elijah G.
API Support Engineer