You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, when you roundtrip an ILookup<TKey, TElement> through MessagePack you end up with an instance that throws a KeyNotFoundException when the key does not exist.
Original: 0
Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'bar' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MessagePack.Formatters.Lookup`2.get_Item(TKey key)
at Program.<Main>$(String[] args) in C:\Users\joelv\Desktop\MessagePackRepro\MessagePackRepro\Program.cs:line 9
C:\Users\joelv\Desktop\MessagePackRepro\MessagePackRepro\bin\Debug\net6.0\MessagePackRepro.exe (process 39896) exited with code -532462766.
Version used: 2.3.85
Runtime: .NET 6
Additional context
You can do a workaround with Contains but this requires two lookups.
Bug description
In
System.Linqthe defaultILookup<TKey, TElement>implementation returns an empty sequence when the provided key does not exist, per https://docs.microsoft.com/en-us/dotnet/api/system.linq.lookup-2.item?view=net-6.0#remarks.However, when you roundtrip an
ILookup<TKey, TElement>through MessagePack you end up with an instance that throws aKeyNotFoundExceptionwhen the key does not exist.Repro steps
Expected behavior
This repro program should show:
Actual behavior
Instead, it shows:
Additional context
You can do a workaround with
Containsbut this requires two lookups.