Skip to content

[Bug]: RemoveKey with AutoRefresh and Filter throws #1119

Description

@jcummings2

Describe the bug 🐞

Upgrading to 9.4.31 caused code with the pattern mentioned in the "Steps to Reproduce" section below to fail in some situations.

It can result in the following Exception:

System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

The bug was introduced with the rewrite of the static list filter logic in #1063. The issue ultimately stems from what seems to a be long standing feature/bug of RemoveKeyEnumerator that sets the CurrentIndex to -1 when a list is not passed into the constructor (or technically when the item isn't found when a list is passed but no callers actually pass a list). Pull request #1120 with unit tests that demonstrate the problem and a fix.

Step to reproduce

        ReadOnlyObservableCollection<Person> collection;
        using var source = new SourceCache<Person, string>(p => p.Key);
        using var subscription = source.Connect()
                .AutoRefresh(x => x.Age)
                .RemoveKey()
                .Filter(x => x.Age > 50)
                .Bind(out collection)
                .Subscribe();

Reproduction repository

https://github.com/jcummings2/DynamicData

Expected behavior

List should be properly updated with filtered list of items from cache.

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

DynamicData Version

9.4.31

Additional information ℹ️

Worked fine in 9.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions