I keep getting this 'ArgumentOutOfRange exception non-negative number required, Parameter name: index', whenever I try to open the page and I can't seem to figure out where/how exactly the negative number is appearing. Thank you all in advance!!
var months = data.OrderBy(x => x.ApproximatedStartDate).Select(x => x.Month).Distinct((x, y) => x == y).OrderBy(x => x).ToList();
var upcomingMonths = months.GetRange(months.IndexOf(DateTime.Today.Month), months.Count - months.IndexOf(DateTime.Today.Month));
I'm getting the exception when the code reads the 'upcomingMonths' variable.
stack trace:
[ArgumentOutOfRangeException: Non-negative number required. Parameter name: index]
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +72
System.Collections.Generic.List`1.GetRange(Int32 index, Int32 count) +4951591
InitializeChartBC()
Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +103
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3811
months.IndexOf(DateTime.Today.Month)must be returning a negative number. The documentation ofIndexOfwill tell you exactly when that will return a negative number. Job done. Learning to read exception information is a vital skill while programming and one you should definitely take the time to learn.