ArgumentNullException in TryGetValueNullable

Hello!
I’ve had several times ArgumentNullException:

1

=======================================================================

    leaves 2 s ago at 11:59:25
---- Exception ----
System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at Bib3.Extension.TryGetValueNullable[TKey,TValue](IDictionary`2 dict, TKey key)
   at Sanderling.ABot.Bot.Bot.ToggleLastAgeStepCountFromModule(IShipUiModule module) in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Bot.cs:line 66
   at Sanderling.ABot.Bot.Task.ModuleTaskExtension.IsActive(IShipUiModule module, Bot bot) in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Task\Module.cs:line 18
   at Sanderling.ABot.Bot.Task.RetreatTask.<get_Component>d__2.MoveNext() in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Task\Retreat.cs:line 78
   at Bib3.Extension.<EnumeratePathToNodeFromTreeDFirst>d__35`1.MoveNext()
   at Bib3.Extension.<EnumeratePathToNodeFromTreeDFirst>d__35`1.MoveNext()
   at Bib3.Extension.<EnumeratePathToNodeFromTreeDFirst>d__35`1.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Sanderling.ABot.EnumerableExtension.<EnumerateSubsequencesStartingWithFirstElement>d__0`1.MoveNext() in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\EnumerableExtension.cs:line 12
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
   at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
   at Sanderling.ABot.Bot.BotExtension.TakeSubsequenceWhileUnwantedInferenceRuledOut(IEnumerable`1 listTaskPath) in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\BotExtension.cs:line 49
   at Sanderling.ABot.Bot.Bot.StepOutputListTaskPath() in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Bot.cs:line 69
   at Sanderling.ABot.Bot.Bot.Step(BotStepInput input) in E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Bot.cs:line 114
2
 ==========================================================================
   
    leaves 0 s ago at 15:18:27
---- Exception ----
System.ArgumentNullException: Значение не может быть неопределенным.
Имя параметра: key
   в System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   в System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   в Bib3.Extension.TryGetValueNullable[TKey,TValue](IDictionary`2 dict, TKey key)
   в Sanderling.ABot.Bot.Bot.ToggleLastAgeStepCountFromModule(IShipUiModule module) в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Bot.cs:строка 66
   в Sanderling.ABot.Bot.Task.ModuleTaskExtension.IsActive(IShipUiModule module, Bot bot) в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Task\Module.cs:строка 18
   в Sanderling.ABot.Bot.Task.RetreatTask.<get_Component>d__2.MoveNext() в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Task\Retreat.cs:строка 78
   в Bib3.Extension.<EnumeratePathToNodeFromTreeDFirst>d__35`1.MoveNext()
   в Bib3.Extension.<EnumeratePathToNodeFromTreeDFirst>d__35`1.MoveNext()
   в Bib3.Extension.<EnumeratePathToNodeFromTreeDFirst>d__35`1.MoveNext()
   в System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   в Sanderling.ABot.EnumerableExtension.<EnumerateSubsequencesStartingWithFirstElement>d__0`1.MoveNext() в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\EnumerableExtension.cs:строка 12
   в System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   в System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
   в System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
   в Sanderling.ABot.Bot.BotExtension.TakeSubsequenceWhileUnwantedInferenceRuledOut(IEnumerable`1 listTaskPath) в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\BotExtension.cs:строка 49
   в Sanderling.ABot.Bot.Bot.StepOutputListTaskPath() в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Bot.cs:строка 69
   в Sanderling.ABot.Bot.Bot.Step(BotStepInput input) в E:\GoogleDrive\EveMole\Reposit\VNIAbot\src\Sanderling.ABot\Bot\Bot.cs:строка 114

The problem is that I can not see the implementation of this method.
I assume that the problem has arisen because of the incorrect recognition of modules. But maybe I’m wrong.

1 Like

From this information, I assume that we can prevent the exception by avoiding the call to TryGetValue when key is null.
A way to implement this is an additional branch for null in ToggleLastAgeStepCountFromModule as seen in this commit I just uploaded:

Thank you, man! This fix solve my problem =)