I have a function called GetSuggestedAddresses and there's is a piece of it which calls a function that returns a List. I also have a property in my class that is type List. I tried using AddRange to add in my returned results to my property but it is throwing a null exception. I tried stepping through the code but I'm a bit lost. Any ideas? Here is my code-
public List<ExpressAddressResult> GetSuggestedAddresses(string format = "xml")
{
foreach (RequestArrayRecord address in reqRecords) {
string result = string.Empty;
NameValueCollection collection = new NameValueCollection();
collection.Add("id", AuthKey);
collection.Add("line1", CleanUpAddress(address.AddressLine1));
collection.Add("city", address.City);
collection.Add("state", address.State);
collection.Add("postalcode", address.Zip);
collection.Add("maxrecords", MaxSuggestionResults.ToString());
collection.Add("format", format);
string parameters = GenerateParameters(collection);
Uri serviceAddress = new Uri(RequestURL + parameters);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
if (response != null) {
using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) {
result = streamReader.ReadToEnd();
}
}
}
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
List<ExpressAddressResult> results = CreateListFromXml(xmlDoc);
if (results != null) {
AddressSuggestions.AddRange(results); // Throws Null Exception
}
}
return AddressSuggestions; // This is a property of type List<ExpressAddressResult>
}