Hello, dear.

I do double sorting on the link (priority sheet), sort it, output it to IEnumerable , but when I try queue.Any() ArgumentException is thrown. Google is already half an hour, but I still can not understand the reason.

Help me to understand.

 private readonly List<BaseBotAction> _actions = new List<BaseBotAction>(); // abstract IEnumerable<BaseBotAction> queue = from action in _actions orderby action.Priority() ascending, action.StartTime ascending select action; if (queue.Any()) { //ArgumentException here var action = queue.First(); // Something... } 

Thrace:

 2013-10-24 20:58:20,714 [Thread-Bot-Manager-PriorityQueue] ERROR EBot.ClientsManager [(null)] - System.ArgumentException: Длина результирующего массива недостаточна. Проверьте значения destIndex и length, а также нижние границы массива. в System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) в System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex) в System.Linq.Buffer`1..ctor(IEnumerable`1 source) в System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext() в System.Linq.Enumerable.Any[TSource](IEnumerable`1 source) в EBot.BotInstance.PriorityQueueRun() в D:\CSharp\EBot\BotInstance.cs:строка 47 
  • Write more details on the exception, eh? Message? InnerException? Stacktrace? - VladD
  • Completely forgot ... Of course, update. True, I had eaten half of the characters as usual. - Yevgeny Karpov
  • one
    @ Yevgeny Karpov: a very strange exception happened: inside the order by suddenly there was not enough allocated buffer. Either in the LINQ bug, or in some way, the collection changed during the execution of Any . --- You are welcome! - VladD

1 answer 1

The exception, apparently, is thrown not in Any() , but when the queue expanded. Try (temporarily, for a test) like this:

 IEnumerable<BaseBotAction> queue = (from action in _actions orderby action.Priority() ascending, action.StartTime ascending select action).ToList(); 

On this line should already fly.


By the way: isn’t someone accidentally _actions from another thread?

  • one
    Yes, I forgot about synchronization, there are changes from another thread. - Yevgeny Karpov