Someone Please help me figure out what I'm doing wrong, Below is the full erroe message that I'm receiving:
Server Error in '/' Application.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An
unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
Line 356: //string ccSubScriptionEndDate = DateTime.Now.AddYears(1).ToShortDateString();
Line 357: CCServiceHelper api = new CCServiceHelper();
Line 358: CCResponseCode response = api.AuthCapture( ccNum, ccExpDate, cardCode, totalOrderAmount, rbPaymentOptions.SelectedValue, "customerIP", customerFirstName, customerLastName, "companyName", "address", address.City, address.State, address.PostalCode, "US", customer.PhoneHome, customer.Email); Line 359:
Line 360:
search videos at Google with debug visual studio 2010
B-) Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
I don't have much access to the source files directly.
i'm do not understand what you mean by the above statement ... you've posted over 500 lines of source code.
Sorry, i just do not have enough free time today to dig through 500+ lines of your source code ... even if i did, please undersstand that the problem is just as likely in your data as it is in the source code ... for that reason, you really need to walk
your code with the debugger ... the debugger is your best friend ...
i'm assuming the you're the programmer and it's youu own code that you need to debug here ... is that the case?
have you even tried to debug your code?
g.
P.S.: study your Stacktrace carefully (work your way BACKWARDS through the Stacktrace to look for clues):
[Argument OutOfRange Exception: Index was out of range.
Must be non-negative and
less than the size of the collection.
Parameter name: index]
double totalOrderAmount = 0.0;
decimal.TryParse(System.Configuration.ConfigurationManager.AppSettings["SubScriptAmt"], out subScriptionAmount);
double.TryParse(System.Configuration.ConfigurationManager.AppSettings["SubScriptInitialPayment"], out subScriptionInitalPayment);
double.TryParse(System.Configuration.ConfigurationManager.AppSettings["SubScriptFullPayment"], out subScriptionFullPayment);
if (subScriptionFullPayment <= 0 && subScriptionInitalPayment <= 0.0 && subScriptionInitalPayment <= 0.0)
{
lblValidation.Text = "Subscription service is unavailable";
return;
}
LinkBlade .... YOU
MUST TRACE as far as necessary ...
if values are passed to SQL server stlored procedures, you need to trace there too ... you can usually, if necessary, trace a SP with tools like SSMS 2008, et cetera.
B-) Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
The error occurs when AuthCapture makes a call to ProcessWebResponse. Unfortunately, as far as I can see, you haven't posted code which has anything to do with the problem.
Put a breakpoint on the first line of AuthCapture and start examining variables and stepping through code.
Sorry, i just do not have enough free time today to dig through 500+ lines of your source code ... even if i did, please undersstand that the problem is just as likely in your data as it is in the source code ... for that reason, you really need to walk
your code with the debugger ... the debugger is your best friend ...
i'm assuming the you're the programmer and it's youu own code that you need to debug here ... is that the case?
have you even tried to debug your code?
@ gerrylowry: Thanks for the advice gerrylowry. I wasn't not the original programmer for this application. As you can see the code it not commented well, what i have are just peaces of this code. I can understand that it is a lot of code to look through
and I appreciate all your efforts to assist me in finding the problem. I've tried to grab what is needed for the form to work and debug it in VS, with no luck in find the solution to my problem.
I do however have the other part of the code which it refers to ProcessWebResponse on Line 314. I am posting the full code which is under 500 lines of code. I appreciate your time and efforts once again in assisting me.
Paul Linton
Thank for the new definition of 'snippet'!
The error occurs when AuthCapture makes a call to ProcessWebResponse. Unfortunately, as far as I can see, you haven't posted code which has anything to do with the problem.
@Paul Linton: Your welcome . Below is teh rest of the offending code. Thanks for your assistance and humor.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Net;
/// <summary>
/// Summary description for CCServiceHelper
/// </summary>
public class CCServiceHelper
{
//could be datadriven enum for now
public enum CreditCartType : int
{
Visa = 1,
MasterCard = 2,
Discover = 3,
AmericanExpress = 4
};
private static List<string> parseResult(string resultString, string delimiter)
{
List<string> responseValuesList = new List<string>();
Array responseArray = resultString.Split(Convert.ToChar(delimiter));
foreach (var item in responseArray)
{
responseValuesList.Add(item.ToString());
}
return responseValuesList;
}
public static string SendWebRequest(string serviceURI, string postString, out string errorMSG)
{
string webResponse = string.Empty;
errorMSG = string.Empty;
try
{
// create an HttpWebRequest object to communicate with Authorize.netserviceURI
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(serviceURI);
objRequest.Method = "POST";
objRequest.ContentLength = postString.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter myWriter = null;
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(postString);
myWriter.Close();
myWriter.Dispose();
// returned values are returned as a stream, then read into a string
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
{
webResponse = responseStream.ReadToEnd();
responseStream.Close();
responseStream.Dispose();
}
}
catch (Exception ex)
{
errorMSG = "PROGRAM ERROR - UNABLE TO SEND WEB REQUEST :: " + ex.Message;
webResponse = string.Empty;
}
finally
{
//should probably check if the resources have been closed and disposed.
}
return webResponse;//returns a string
}
public static bool IsValidCreditCard(string cardNumber, int cardType)
{
byte[] number = new byte[16]; // number to validate
// Remove non-digits
int len = 0;
for (int i = 0; i < cardNumber.Length; i++)
{
if (char.IsDigit(cardNumber, i))
{
if (len == 16)
return false; // number has too many digits
number[len++] = byte.Parse(cardNumber[i].ToString());
}
}
// Validate based on card type, first if tests length, second tests prefix
switch (cardType)
{
case 2: //mastercard
if (len != 16)
return false;
if (number[0] != 5 || number[1] == 0 || number[1] > 5)
return false;
break;
case 1: //visa
if (len != 16 && len != 13)
return false;
if (number[0] != 4)
return false;
break;
case 4: //American Express
if (len != 15)
return false;
if (number[0] != 3 || (number[1] != 4 && number[1] != 7))
return false;
break;
case 3: //Discover
if (len != 16)
return false;
if (number[0] != 6 || number[1] != 0 || number[2] != 1 || number[3] != 1)
return false;
break;
}
// Use Luhn Algorithm to validate
int sum = 0;
for (int i = len - 1; i >= 0; i--)
{
if (i % 2 == len % 2)
{
int n = number[i] * 2;
sum += (n / 10) + (n % 10);
}
else
sum += number[i];
}
return (sum % 10 == 0);
}
public static bool IsValidEmail(string email)
{
const string emailPattern = @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
Regex regEmailPattern = new Regex(emailPattern);
if (regEmailPattern.IsMatch(email))
{ return true; }
else
{ return false; }
}
public static bool IsStrongPassword(string pass)
{
string emailPattern = @"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{" + ConfigurationManager.AppSettings["MinPasswordLength"] + ",10})$";
Regex regEmailPattern = new Regex(emailPattern);
if (regEmailPattern.IsMatch(pass))
{ return true; }
else
{ return false; }
}
public static bool IsValidSsn(string email)
{
const string emailPattern = @"^\d{3}-\d{2}-\d{4}$";
Regex regEmailPattern = new Regex(emailPattern);
if (regEmailPattern.IsMatch(email))
{ return true; }
else
{ return false; }
}
public static bool IsValidUSZipCode(string zipCode)
{
const string pattern = @"^\d{5}(-?\d{4})?$";
Regex regPattern = new Regex(pattern);
if (regPattern.IsMatch(zipCode))
{ return true; }
else
{ return false; }
}
public static string GetExpirationDate(int expMonth, int expYear)
{
string rtn=String.Empty;
if (expMonth <= 0 || expYear <= 0 || expYear.ToString().Length > 5)
{
return rtn;
}
else
{
if (expMonth < 10)
{
rtn = "0" + expMonth.ToString();
}
else
{
rtn = expMonth.ToString();
}
return rtn + expYear.ToString().Substring(2, 2);
}
}
public static string BuildAuthCapture(string LoginID, string TransKey, string clientKey,
string ccNum, string expDate, string cardCode,
double totalOrderAmount, string transactionType, string clientInvoiceNo,
string customerIP, string customerFirstName, string customerLastName,
string customerCompany, string customerAddress, string customerCity, string customerStateAbbr, string customerZip,
string customerCountry, string customerPhone, string customerEmail, string ReOccuringBilling)
{
Hashtable post_values = new Hashtable();
post_values.Add("x_login",LoginID); //authorize login
post_values.Add("x_tran_key",TransKey); //authorize transkey
post_values.Add("x_version", "3.1"); //indicates the fields the system expects.
// post_values.Add("x_test_request", "TRUE"); //- NEEDS TO BE FALSE FOR PRODUCTION.
post_values.Add("x_delim_data", "TRUE"); //this should always be true.
post_values.Add("x_relay_response", "FALSE"); //this should always be false.
post_values.Add("x_delim_char", '|'); //this should always be a pipe char.
post_values.Add("x_card_num", ccNum); //length of 22
post_values.Add("x_exp_date", expDate); //MMYY
post_values.Add("x_card_code", cardCode); //number on back of card - length of 4
post_values.Add("x_amount", totalOrderAmount); //total amount to charge INCLUDING TAX!
post_values.Add("x_method", "CC"); //ONLY DOING CREDIT CARDS.
post_values.Add("x_type", transactionType);
//post_values.Add("x_recurring_billing", ReOccuringBilling); //takes "YES" or "NO"
//post_values.Add("x_cust_id", clientKey); //Need to send along the ClientKey so it is returned in the response.
post_values.Add("x_invoice_num", clientInvoiceNo); //Client invoice no.
post_values.Add("x_description", customerIP); //customer IP is not returned so need to include it here because this is returned.
//post_values.Add("x_customer_ip", customerIP); //WE SHOULD BE STORING THIS IN THE TRANSACTION TO FRAUD REASONS.
post_values.Add("x_first_name", customerFirstName);
post_values.Add("x_last_name", customerLastName);
post_values.Add("x_company", customerCompany);
post_values.Add("x_address", customerAddress);
post_values.Add("x_zip", customerZip);
post_values.Add("x_city", customerCity);
post_values.Add("x_state", customerStateAbbr); //valid state abbr.
post_values.Add("x_country", customerCountry); //valid country abbr.
post_values.Add("x_phone", customerPhone); //needs to be (xxx)xxx-xxxx
post_values.Add("x_email", customerEmail);
String post_string = "";
foreach (DictionaryEntry field in post_values)
{
post_string += field.Key + "=" + field.Value + "&";
}
post_string = post_string.TrimEnd('&');
return post_string;
}
public CCResponseCode AuthCapture(string ccNum, string expDate, string cardCode,
double totalOrderAmount, string clientInvoiceNo, string customerIP,
string customerFirstName, string customerLastName, string customerCompany,
string customerAddress, string customerCity, string customerStateAbbr, string customerZip,
string customerCountry, string customerPhone, string customerEmail)
{
CCResponseCode rtn = null;
string transactionType = "AUTH_CAPTURE";
string serviceURI = AppSettings.AuthorizeProdUri;
string returnErrorMSG = string.Empty;
string LoginID = AppSettings.AuthorizeApiKey;
string TransKey = AppSettings.AuthorizeTransKey; //transkey
string postString = string.Empty;
string webRequestResponse = string.Empty;
postString = BuildAuthCapture(LoginID, TransKey, "", ccNum, expDate, cardCode,
totalOrderAmount, transactionType, clientInvoiceNo, customerIP,
customerFirstName, customerLastName, customerCompany,
customerAddress, customerCity, customerStateAbbr, customerZip,
customerCountry, customerPhone, customerEmail,"");
webRequestResponse = SendWebRequest(serviceURI, postString, out returnErrorMSG);
if (returnErrorMSG == string.Empty)
{
CCResponseCode authCaptureResult = ProcessWebResponse(webRequestResponse);
rtn = authCaptureResult;
}
return rtn;
}
public static CCResponseCode ProcessWebResponse(string webRequestResponse)
{
List<string> responseValuesList = new List<string>();
string responseForCustomer = string.Empty;
string serviceResponseCode = string.Empty; //1=Approved,2=Declined,3=Error,4=UnderReview
string serviceResponseSubCode = string.Empty; //Used by gateway for internal tracking
string serviceResponseReasonCode = string.Empty; //Detailed Reason Code
string serviceResponseReasonText = string.Empty; //Response Reason Text
string serviceResponseAuthCode = string.Empty; //Authorization Code
string serviceResponseAVSCode = string.Empty; //Address Verification Service (AVS) response
string serviceResponseTransID = string.Empty; //Transaction ID
string clientInvoiceNo = string.Empty;
string transactionDescription = string.Empty; //CUSTOMER IP (because not returned elsewhere)
string transactionAmount = string.Empty;
string transactionMethod = string.Empty;
string tranactionType = string.Empty;
string clientKey = string.Empty; //Actually the Customer ID field.
string customerFirstName = string.Empty;
string customerLastName = string.Empty;
string customerCompany = string.Empty;
string customerAddress = string.Empty;
string customerCity = string.Empty;
string customerState = string.Empty;
string customerZip = string.Empty;
string customerCountry = string.Empty;
string customerPhone = string.Empty;
string customerEmail = string.Empty;
string serviceResponseMD5Hash = string.Empty; //Gateway MD5 Hash value for authentication purposes.
string serviceResponseCardCode = string.Empty; //Card Code Verification (CCV) response
string serviceResponseCAVCode = string.Empty; //Cardholder Auth Verification Response
responseValuesList = parseResult(webRequestResponse, "|");
serviceResponseCode = responseValuesList[0].ToString();
serviceResponseSubCode = responseValuesList[1].ToString();
serviceResponseReasonCode = responseValuesList[2].ToString();
serviceResponseReasonText = responseValuesList[3].ToString();
serviceResponseAuthCode = responseValuesList[4].ToString();
serviceResponseAVSCode = responseValuesList[5].ToString();
serviceResponseTransID = responseValuesList[6].ToString();
clientInvoiceNo = responseValuesList[7].ToString();
transactionDescription = responseValuesList[8].ToString();
transactionAmount = responseValuesList[9].ToString();
transactionMethod = responseValuesList[10].ToString();
tranactionType = responseValuesList[11].ToString();
clientKey = responseValuesList[12].ToString();
customerFirstName = responseValuesList[13].ToString();
customerLastName = responseValuesList[14].ToString();
customerCompany = responseValuesList[15].ToString();
customerAddress = responseValuesList[16].ToString();
customerCity = responseValuesList[17].ToString();
customerState = responseValuesList[18].ToString();
customerZip = responseValuesList[19].ToString();
customerCountry = responseValuesList[20].ToString();
customerPhone = responseValuesList[21].ToString();
customerEmail = responseValuesList[23].ToString();
serviceResponseMD5Hash = responseValuesList[37].ToString();
serviceResponseCardCode = responseValuesList[38].ToString();
serviceResponseCAVCode = responseValuesList[39].ToString();
CCResponseCode responseCode = new CCResponseCode();
responseCode.ResponseCode = serviceResponseCode.Trim();
responseCode.Message = GetResponseCodeDetails(serviceResponseReasonCode, serviceResponseReasonText);
responseCode.AuthCode = serviceResponseAuthCode.Trim();
responseCode.TransactionID = serviceResponseTransID.Trim();
return responseCode;
}
private static string GetResponseCodeDetails(string responseReasonCode, string responseReasonText)
{
string responseDetails = string.Empty;
switch (responseReasonCode)
{
case "1":
responseDetails = "TRANSACTION APPROVED!";
break;
case "2":
responseDetails = "TRANSACTION DECLINED";
break;
case "3":
responseDetails = "TRANSACTION APPROVED!"; //default action is to approve on error and sort out later approves error
break;
case "4":
responseDetails = "TRANSACTION DECLINED - CUT UP CARD";
break;
case "5":
responseDetails = "PROCESSING ERROR - INVALID AMOUNT";
break;
case "6":
responseDetails = "PROCESSING ERROR - INVALID CREDIT CARD NUMBER";
break;
case "7":
responseDetails = "PROCESSING ERROR - INVALID EXPIRATION DATE";
break;
case "8":
responseDetails = "PROCESSING ERROR - CREDIT CARD EXPIRED";
break;
case "9":
responseDetails = "PROCESSING ERROR - ABA CODE IS INVALID";
break;
case "10":
responseDetails = "PROCESSING ERROR - BANK ACCOUNT NUMBER IS INVALID";
break;
case "11":
responseDetails = "PROCESSING ERROR - DUPLICATE TRANSACTION";
break;
case "12":
responseDetails = "PROCESSING ERROR - AUTHORIZATION CODE REQUIRED";
break;
case "13":
responseDetails = "PROCESSING ERROR - LOGIN ID INVALID!!";
break;
case "14":
responseDetails = "PROCESSING ERROR - URL IS INVALID";
break;
case "15":
responseDetails = "PROCESSING ERROR - INVALID TRANSACTION ID";
break;
case "16":
responseDetails = "PROCESSING ERROR - TRANSACTION NOT FOUND";
break;
case "17":
responseDetails = "PROCESSING ERROR - CREDIT CARD TYPE NOT ACCEPTED";
break;
case "18":
responseDetails = "PROCESSING ERROR - E-CHECKS NOT ACCEPTED";
break;
case "19":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "20":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "21":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "22":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "23":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "24":
responseDetails = "PROCESSING ERROR - TERMINAL ID INCORRECT";
break;
case "25":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "26":
responseDetails = "PROCESSING ERROR - TIMEOUT - TRY AGAIN LATER";
break;
case "27":
responseDetails = "AUTHORIZATION DENIED - ADDRESS DOES NOT MATCH ADDRESS ON CARD";
break;
case "28":
responseDetails = "AUTHORIZATION DENIED - CARD TYPE NOT ACCEPTED";
break;
case "29":
responseDetails = "AUTHORIZATION DENIED - INVALID PAYMENTECH ID NUMBER";
break;
case "30":
responseDetails = "AUTHORIZATION DENIED - INVALID CONFIGURATION";
break;
default:
responseDetails = "AUTHORIZATION DENIED - " + responseReasonText;
break;
}
return responseDetails;
}
}
public sealed class CCResponseCode
{
public string ResponseCode { get; set; }
public string Message { get; set; }
public string AuthCode { get; set; }
public string TransactionID { get; set; }
}
if you do not know how to use the debugger, you need to stop now, do not pass GO, and learn how to used the
debugger ... you can use the links that i provided above, at
http://forums.asp.net/post/5128479.aspx ...
LinkBlade, you are
not listening to me ... the clue to your problem lies at
this is another reason why you must use the debugger ... the debugger always will show you what the code
actually does (not what any misleading comments might suggest that the code does).
LinkBlade
I've tried to grab what is needed for the form to work and debug it in VS, with no luck in find the solution to my problem.
then you must debug it again and again in vs;
also, if you have ms SQL SP's, then you must
debug them with a tool like SSMS.
LinkBlade, study your
data too ... remember this: bad data breaks good code!!!
as i wrote earlier, your problem may be bad data in your database.
-- where are you storing your data?
-- what data values are used in line 358 when you crash (the
debugger will tell you this).
g.
B-) Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
What does the response that comes back look like? My guess is that whoever is providing the service has changed the structure of the response, it looks to me that they are no longer using the '|' character as a separator or the response may be empty.
If you can't debug the code then you can probably use a packet sniffing sort of tool (one example is fiddler) to at least see if you are getting a sensible response from the web service. If the response is not in the format that the code expects then it
is time to start rewriting.
None
0 Points
3 Posts
Index was out of range. Must be non-negative and less than the size of the collection. Parameter...
Aug 30, 2012 03:19 PM|LinkBlade|LINK
Someone Please help me figure out what I'm doing wrong, Below is the full erroe message that I'm receiving:
Server Error in '/' Application.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
Line 356: //string ccSubScriptionEndDate = DateTime.Now.AddYears(1).ToShortDateString(); Line 357: CCServiceHelper api = new CCServiceHelper(); Line 358: CCResponseCode response = api.AuthCapture( ccNum, ccExpDate, cardCode, totalOrderAmount, rbPaymentOptions.SelectedValue, "customerIP", customerFirstName, customerLastName, "companyName", "address", address.City, address.State, address.PostalCode, "US", customer.PhoneHome, customer.Email); Line 359: Line 360:
Source File: d:\Inetpub\wwwroot\UserControls\AddUpForm.ascx.cs Line: 358
Stack Trace:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
I can provide code later for review.
Star
14297 Points
5880 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 30, 2012 04:44 PM|gerrylowry|LINK
@ LinkBlade
use the debugger* ...
Line 358: CCResponseCode response
= api.AuthCapture( ccNum, ccExpDate, cardCode, totalOrderAmount,
rbPaymentOptions.SelectedValue, "customerIP", customerFirstName,
customerLastName, "companyName", "address", address.City,
address.State, address.PostalCode, "US", customer.PhoneHome, customer.Email);
please carefully check out the values of the above parameters ... via the debugger*, you should be able to discover the offending value.
g.
* walking your code with your debugger:
video, c. 8 minutes: http://msdn.microsoft.com/en-ca/vstudio/ee672313.aspx
"How Do I: Step with The Debugger in Visual Studio?"
Debugging: http://lmgtfy.com/?q=debug+visual+studio+2010
example: http://www.codeproject.com/KB/cs/MasteringInDebugging.aspx
videos: http://www.youtube.com/watch?v=z5gBIizwsY0
search videos at Google with debug visual studio 2010
None
0 Points
3 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 30, 2012 07:13 PM|LinkBlade|LINK
Thanks for the reply gerrylowry. I don't have much access to the source files directly.
I can post a snippet of the code for your review.:
Star
14297 Points
5880 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 30, 2012 09:48 PM|gerrylowry|LINK
@ LinkBlade
i'm do not understand what you mean by the above statement ... you've posted over 500 lines of source code.
Sorry, i just do not have enough free time today to dig through 500+ lines of your source code ... even if i did, please undersstand that the problem is just as likely in your data as it is in the source code ... for that reason, you really need to walk your code with the debugger ... the debugger is your best friend ...
i'm assuming the you're the programmer and it's youu own code that you need to debug here ... is that the case?
have you even tried to debug your code?
g.
P.S.: study your Stacktrace carefully (work your way BACKWARDS through the Stacktrace to look for clues):
[Argument OutOfRange Exception:
Index was out of range.
Must be non-negative and less than the size of the collection.
Parameter name: index]
===> Source File: d:\Inetpub\wwwroot\UserControls\AddUpForm.ascx.cs Line: 358
System.Collections.Generic.List`1.get_Item(Int32 index) +9593284
UserControls_AddUpForm
.ProcessCustomer(
DateTime dob,
Address address,
Customer customer, <===== valid number ?????
String password,
String ccNum,
String ccExpDate,
String customerFirstName,
String customerLastName,
String cardCode,
String clientInvoiceNo)
in d:\Inetpub\wwwroot\UserControls\AddUpForm.ascx.cs:358 <================= !!!!!!!!
UserControls_AddUpForm
.btnSubmit_Click(Object sender, EventArgs e) in d:\Inetpub\wwroot\UserControls\AddUpForm.ascx.cs:213
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
******************* you're dying here: [ you need to debug this !!!!!!!!!!!!! ]
private void ProcessCustomer
( DateTime dob, Address address, Customer customer,string password, string ccNum, string ccExpDate, string customerFirstName,string customerLastName, string cardCode, string clientInvoiceNo)
{
//process
decimal subScriptionAmount = 0;
double subScriptionInitalPayment = 0.0;
double subScriptionFullPayment = 0.0;
double totalOrderAmount = 0.0;
decimal.TryParse(System.Configuration.ConfigurationManager.AppSettings["SubScriptAmt"], out subScriptionAmount);
double.TryParse(System.Configuration.ConfigurationManager.AppSettings["SubScriptInitialPayment"], out subScriptionInitalPayment);
double.TryParse(System.Configuration.ConfigurationManager.AppSettings["SubScriptFullPayment"], out subScriptionFullPayment);
if (subScriptionFullPayment <= 0 && subScriptionInitalPayment <= 0.0 && subScriptionInitalPayment <= 0.0)
{
lblValidation.Text = "Subscription service is unavailable";
return;
}
if (rbPaymentOptions.SelectedValue.ToLower() == "full")
{
totalOrderAmount = subScriptionFullPayment;
}
else
{
totalOrderAmount = subScriptionInitalPayment;
}
string resultMsg = string.Empty;
//string ccSubScriptionEndDate = DateTime.Now.AddYears(1).ToShortDateString();
CCServiceHelper api = new CCServiceHelper();
CCResponseCode response
= api.AuthCapture
( ccNum, ccExpDate, cardCode, totalOrderAmount, rbPaymentOptions.SelectedValue, "customerIP", customerFirstName, customerLastName, "companyName", "address", address.City, address.State, address.PostalCode, "US", customer.PhoneHome, customer.Email);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
===================== VALUES PASSED IN ==========
( DateTime dob, Address address, Customer customer,string password,
string ccNum, <============ ???????????????
string ccExpDate, string customerFirstName,string customerLastName, string cardCode, string clientInvoiceNo)
===================== VALUES PASSED ONWARDS ==========
( ccNum, ccExpDate, cardCode, totalOrderAmount, rbPaymentOptions.SelectedValue, "customerIP", customerFirstName, customerLastName, "companyName", "address", address.City, address.State, address.PostalCode, "US", customer.PhoneHome, customer.Email);
LinkBlade .... YOU MUST TRACE as far as necessary ...
if values are passed to SQL server stlored procedures, you need to trace there too ... you can usually, if necessary, trace a SP with tools like SSMS 2008, et cetera.
Star
9555 Points
2785 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 30, 2012 11:06 PM|Paul Linton|LINK
The error occurs when AuthCapture makes a call to ProcessWebResponse. Unfortunately, as far as I can see, you haven't posted code which has anything to do with the problem.
Put a breakpoint on the first line of AuthCapture and start examining variables and stepping through code.
None
0 Points
3 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 31, 2012 11:58 AM|LinkBlade|LINK
@ gerrylowry: Thanks for the advice gerrylowry. I wasn't not the original programmer for this application. As you can see the code it not commented well, what i have are just peaces of this code. I can understand that it is a lot of code to look through and I appreciate all your efforts to assist me in finding the problem. I've tried to grab what is needed for the form to work and debug it in VS, with no luck in find the solution to my problem.
I do however have the other part of the code which it refers to ProcessWebResponse on Line 314. I am posting the full code which is under 500 lines of code. I appreciate your time and efforts once again in assisting me.
@Paul Linton: Your welcome
. Below is teh rest of the offending code. Thanks for your assistance and humor.
Star
14297 Points
5880 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 31, 2012 12:51 PM|gerrylowry|LINK
@ LinkBlade
if you do not know how to use the debugger, you need to stop now, do not pass GO, and learn how to used the debugger ... you can use the links that i provided above, at http://forums.asp.net/post/5128479.aspx ...
LinkBlade, you are not listening to me ... the clue to your problem lies at
Line 358: CCResponseCode response
= api.AuthCapture( ccNum, ccExpDate, cardCode, totalOrderAmount,
rbPaymentOptions.SelectedValue, "customerIP", customerFirstName,
customerLastName, "companyName", "address", address.City,
address.State, address.PostalCode, "US", customer.PhoneHome, customer.Email);
please reread everything that i have posted.
this is another reason why you must use the debugger ... the debugger always will show you what the code actually does (not what any misleading comments might suggest that the code does).
then you must debug it again and again in vs;
also, if you have ms SQL SP's, then you must
debug them with a tool like SSMS.
LinkBlade, study your data too ... remember this: bad data breaks good code!!!
as i wrote earlier, your problem may be bad data in your database.
-- where are you storing your data?
-- what data values are used in line 358 when you crash (the debugger will tell you this).
g.
Star
9555 Points
2785 Posts
Re: Index was out of range. Must be non-negative and less than the size of the collection. Parame...
Aug 31, 2012 08:09 PM|Paul Linton|LINK
What does the response that comes back look like? My guess is that whoever is providing the service has changed the structure of the response, it looks to me that they are no longer using the '|' character as a separator or the response may be empty.
If you can't debug the code then you can probably use a packet sniffing sort of tool (one example is fiddler) to at least see if you are getting a sensible response from the web service. If the response is not in the format that the code expects then it is time to start rewriting.