3
votes

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:

Out of range

Here's the StackTrace:

at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.Collections.Generic.List1.get_Item(Int32 index) at System.Collections.ObjectModel.Collection1.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?

1
I'm pretty certain exceptions are always right.Grant Thomas
@GrantThomas Completely agree, but check out the screenshot and you will see why I'm confused!JMK
do you use multithreading in some place to access Wagers ?Tigran
What does the stack trace say? Is it possible that WagerType does some indexed access in its get?Damien_The_Unbeliever
Look for stack trace (click View Detail) or just catch an exception and print a stack trace. It's not clear where exactly exception is thrown.default locale

1 Answers

1
votes
 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.