danesparza / MailChimp.NET

:envelope: .NET Wrapper for the MailChimp v2.0 API
MIT License
179 stars 119 forks source link

Groupings and GroupInterests #191

Open spyguyhi opened 8 years ago

spyguyhi commented 8 years ago

I am not sure if I am trying to create a Grouping with GroupInterests correctly. I keep getting a "An exception of type 'System.NullReferenceException' occurred in myproject.DLL but was not handled in user code". Here's a sample of my code:

// Create and populate Groupings for Giving Interests then add to MergeVar
MailChimp.Lists.Grouping givingGroup = new MailChimp.Lists.Grouping();
givingGroup.Name = "GIVING_INTERESTS";
// Interest list is a comman delimited list in the GIVING_INTERESTS field in the SPROC
List<string> groupInterests_GI = row["GIVING_INTERESTS"].ToString().Split(',').ToList<string>();
for (int i = 0; i < groupInterests_GI.Count; i++)
{                               
    MailChimp.Lists.Grouping.GroupInterest interest = new MailChimp.Lists.Grouping.GroupInterest();
    interest.Name = groupInterests_GI[i].ToString();
    interest.Interested = true;
    givingGroup.GroupInterests.Add(interest);
}

what am I doing wrong?