Reputation: 28059
I have the following method:
private void DetermineIfWagerIsValid(CouponViewModel result, Bet bet, string wagerType, int selectionCount)
{
if (bet.Wagers[0].WagerType == wagerType) //error here
{
if (bet.Selections.Count != selectionCount)
{
bet.BetStatus = BetStatus.FilledInAndInvalid;
}
}
}
Simple enough, but I am getting an intermittent 'Index out of range' error, when the index doesn't appear to be out of range:
Here's the StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.Collections.Generic.List
1.get_Item(Int32 index) at System.Collections.ObjectModel.Collection
1.get_Item(Int32 index)
at Arkle.CouponProcessing.Scan.LonglistDecoder_994550.DetermineIfWagerIsValid(CouponViewModel result, Bet bet, String wagerType, Int32 selectionCount) in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:line 117 at Arkle.CouponProcessing.Scan.LonglistDecoder_994550.DetermineIfBetIsValid(CouponViewModel result) in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:line 107 at Arkle.CouponProcessing.Scan.LonglistDecoder_994550.Decode() in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:line 62 at ArkleWPF.UI.SlipScanning.CouponTools.DecodeCoupon(Image img, OMRForm omrForm1, CouponDecoder decoder, CouponPrintingInformation viewSettings, String slipBarcode, DecodeStatus status) in C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:line 215
at ArkleWPF.UI.SlipScanning.CouponTools.ProcessForm(OMRForm omrForm1, DecodeStatus status, CouponPrintingInformation viewSettings, Boolean alwaysLotto) in C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:line 89
at ArkleWPF.UI.SlipScanning.CouponTools._Closure$__1._Lambda$__1() in C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:line 27
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
It's not happening every time, it's more like every second or third time and it's driving me crazy! Any ideas?
Upvotes: 3
Views: 4379
Reputation: 19407
System.Collections.Generic.List1.get_Item(Int32 index) at
System.Collections.ObjectModel.Collection1.get_Item(Int32 index)
The requested index does not exist in the list lookup. Wagers
is an array but WagerType
does not have the requested index. The exception
is being raised from within the list's get
statement.
Upvotes: 1