MissingKeyException on Update
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}";
}
This is another issue which sailed by me when it was raised.
You're right, it should just work and thanks for the replication.
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.