private void CheckForErrors(ANetApiResponse response) { if (response.GetType() == typeof(createCustomerProfileTransactionResponse)) { var createCustomerProfileTransactionResponse = (createCustomerProfileTransactionResponse)response; createCustomerProfileTransactionResponse.directResponse = _xmlDoc.ChildNodes[1].ChildNodes[1].InnerText; response = createCustomerProfileTransactionResponse; return; } if (response.messages.message.Length > 0 && response.messages.resultCode == messageTypeEnum.Error) { var stringBuilder = new StringBuilder(); for (var i = 0; i < response.messages.message.Length; i++) { stringBuilder.AppendFormat("Error processing request: {0} - {1}", response.messages.message[i].code, response.messages.message[i].text); } throw new InvalidOperationException(stringBuilder.ToString()); } }