3

我有以下方法:

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;
        }
    }
}

很简单,但是当索引似乎没有超出范围时,我会收到间歇性的“索引超出范围”错误:

超出范围

这是堆栈跟踪:

在 System.ThrowHelper.ThrowArgumentOutOfRangeException() 在 System.Collections.Generic.List 1.get_Item(Int32 index) at System.Collections.ObjectModel.Collection1.get_Item(Int32 索引)
在 Arkle.CouponProcessing.Scan.LonglistDecoder_994550.DetermineIfWagerIsValid(CouponViewModel 结果, Bet bet, String wagerType, Int32 selectionCount) 中 c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:Arkle.CouponProcessing 的第 117 行。 Scan.LonglistDecoder_994550.DetermineIfBetIsValid(CouponViewModel result) in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs: 第 107 行 Arkle.CouponProcessing.Scan.LonglistDecoder_994550.Decode() in c:\code\Arkle \Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:第 62 行 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:第 215 行
在 ArkleWPF.UI.SlipScanning.CouponTools.ProcessForm(OMRForm omrForm1, DecodeStatus status, CouponPrintingInformation viewSettings, Boolean alwaysLotto) 在 C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:ArkleWPF.UI 的第 89
行。 C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb 中的 SlipScanning.CouponTools._Closure$__1._Lambda$__1():
System.Threading.ThreadHelper.ThreadStart_Context(对象状态)的第 27 行
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run System.Threading.ThreadHelper.ThreadStart() 处的(ExecutionContext executionContext、ContextCallback 回调、对象状态)

它不是每次都发生,更像是每秒钟或第三次,它让我发疯!有任何想法吗?

4

1 回答 1

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

于 2013-03-11T11:24:32.700 回答