DynamicData icon indicating copy to clipboard operation
DynamicData copied to clipboard

MissingKeyException on Update

Open aguahombre opened this issue 4 years ago • 1 comments

I'm getting a MissingKeyException 1 is missing from previous value on update. Object type MyType, Key type System.Int32, Group key type System.String

This occurs using a SourceCache<MyType, int> when using Group. I have a application that receives a updates of arrays of MyType which should replace the previous set of data.

The exception arises when the source data has duplicate keys that will be grouped into different groups. I can solve the problem by removing duplicates using DistinctBy on the source data but I was expecting this to work without pre-filtering.

Here is a simplified program that exhibits the problem on DynamicData 7.4.1

    class Program
    {
        static void Main(string[] args)
        {
            SourceCache<Mytype, int> cache = new(x => x.Key);
            List<Mytype> listWithDuplicates = new() 
            { 
                new(1, "G1"), 
                new(1, "G2"),
            };
            cache
                .Connect()
                .Group(x => x.Grouping)
                .Subscribe();

            cache.Edit(x =>
            {
                x.AddOrUpdate(listWithDuplicates);
                x.Clear();
                x.AddOrUpdate(listWithDuplicates);
            });
        }
    }

    class Mytype
    {
        public Mytype(int key, string grouping)
        {
            Key = key;
            Grouping = grouping;
        }

        public int Key { get; set; }
        public string Grouping { get; set; }

        public override string ToString() => $"{Key}, {Grouping}";
    }

aguahombre avatar Oct 28 '21 18:10 aguahombre

This is another issue which sailed by me when it was raised.

You're right, it should just work and thanks for the replication.

RolandPheasant avatar Apr 29 '22 17:04 RolandPheasant

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 10 '22 01:12 github-actions[bot]