So - I still can't figure out why this line:
List<string> strTemp = new List<string>();
Would throw this error:
Index was outside the bounds of the array.
Some context: Recursive function, called (initially) from function launched in separate thread from Web Service (IIS).
Also - lest too many jump in with "perhaps you are looking at the wrong line..." - no. easily confirmed. Move line, moves error, with each deployment.
Oh - and for the record - not always, it's an occasional (they're so much fun). From what I can see in the event log, no issues "around" the time of the flagging that would indicate any complicating factor.
Edit: some details for the comments below.
public class for service: SuperCloud
public class for queuer: PHQ
public function (called from service): void OnStop()
public function causing error: (snip from decl to line in question)
public string CoalesceStrings(List<string> strIn, string[] strDelim = null)
{
string strReturn;
List<string> strTempReturn;
List<string> strTemp = new List<string>(); //<== error here!
string[][] strTemp2;
int iCount, iCap = int.MaxValue;
if (strDelim == null)
strDelim = new string[] { "." };
iCount = strIn.Count;
strTemp2 = new string[iCount][];
for (int i = 0; i < iCount; i++)
{
strTemp2[i] = strIn[i].Split(strDelim, StringSplitOptions.None);
if (strTemp2[i].Length < iCap)
iCap = strTemp2[i].Length;
}
strTempReturn = new List<string>();
if (strDelim[0] == ".")
--iCap;
for (int i = 0; i < iCap; i++)
{
bool bMatch = true;
strTemp.Clear();
strTemp.Add( strTemp2[0][i] );
for (int j = 1; j < iCount; j++)
{
strTemp.Add(strTemp2[j][i]);
if (bMatch && (strTemp2[j][i] != strTemp2[0][i]))
bMatch = false;
}
if (bMatch)
strTempReturn.Add(strTemp2[0][i]);
else if (strDelim[0] == "." )
strTempReturn.Add( CoalesceStrings( strTemp, new string [] {"_"} ));
}
if (strDelim[0] == ".")
strTempReturn.Add(strTemp2[0][strTemp2[0].Length - 1]);
if (strTempReturn.Count == 0)
strReturn = "";
else
{
strReturn = strTempReturn[0];
for (int i = 1; i < strTempReturn.Count; i++)
strReturn = string.Concat(strReturn, strDelim[0], strTempReturn[i]);
}
return strReturn;
}
edited: added full function for mjwillis call: CoalesceStrings(strFileName);
basically: the function will take a set of files that originated from a single file, that were split, according to an unknown algorithm, and "unsplit" it, to get the original file name. The logic itself works (the times it doesn't throw the error).
example: input: { "foo.bar.1.1.prelim", "foo.bar.1.1.final", "foo.bar.1.2.prelim",...,"foo.bar.4.5.final" } output: "foo.bar"