Otis,
I am getting an intermittent ThrowArgumentOutOfRangeException in a ASP.NET. I have looked through all related messages for this and it appears you have fixed several bugs around this same issue (search for ThrowArgumentOutOfRangeException - there are 5 related threads). In my particular case, I CANNOT reproduce it. My web application logs this error and I get anywhere from 0-5 of these errors per day.
I was using the builds/templates/etc from 12-05-2006 of 2.0. I have just downloaded the latest templates and library code to see if that helps, but I don't see anything in the change logs about this issue.
The error stack is:
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.get_Item(Int32 index)
at Wizard.StepMain_Deactivate(Object sender, EventArgs e)
at System.Web.UI.WebControls.View.OnDeactivate(EventArgs e)
at System.Web.UI.WebControls.MultiView.set_ActiveViewIndex(Int32 value)
at System.Web.UI.WebControls.Wizard.set_ActiveStepIndex(Int32 value)
at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object source, EventArgs args)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.wizard_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The code where it fails, loads an existing collection with some data. In my case, I have a field that determines how many 1:n child records I should have. So, I override the anEntity.RelatedCollection property and make sure the collection contains at least the number of child records. I then loop through them. It is in this loop where I get the error - even though I have just verified the correct number is present:
My override code is simple like:
public override a1NRelatedCollection RelatedCollection
{
get
{
if (base.RelatedCollection.Count < RelatedQuantity)
{
for (int x = 0; x < RelatedQuantity- base.RelatedCollection.Count; x++)
{
base.RelatedCollection.Add(new RelatedEntity());
}
}
return base.RelatedCollection;
}
}
and the code that loops is like:
int quantity=10;
anEntity.RelatedQuantity = quantity; //make sure it knows how many we need!
a1NRelatedCollection someList = anEntity.RelatedCollection;
for (int x = 0; x < quantity; x++)
{
someList[x].SetNewFieldValue(3, "somevalue");
}
(note, I guess I could use a "foreach loop" - but I would still have to have iteration variables for other uses in the code, so that is why it is a "for loop" - should work though!)
Again, the code works most of the time and I cannot track down what the problem might be. I figured it was in LLBLGen, since I know the collection size and verify it right before I loop through it.
Any ideas or suggestions?