Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingKeyException on Update #527

Closed
aguahombre opened this issue Oct 28, 2021 · 2 comments · Fixed by #666
Closed

MissingKeyException on Update #527

aguahombre opened this issue Oct 28, 2021 · 2 comments · Fixed by #666

Comments

@aguahombre
Copy link

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}";
    }
@RolandPheasant
Copy link
Collaborator

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

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

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants