0

Can I have a reliable dictionary which holds another reliable dictionary as its value?

var dicts = await StateManager.GetOrAddAsync<IReliableDictionary<string, IReliableDictionary<string, string>>>("Dictionaries");

My first try gave a serialization error:

Type 'Microsoft.ServiceFabric.Data.Collections.DistributedDictionary`2[System.String,System.String]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.
If the type is a collection, consider marking it with the CollectionDataContractAttribute.
See the Microsoft .NET Framework documentation for other supported types.

Preben Huybrechts
  • 5,853
  • 2
  • 27
  • 63
Sammy
  • 885
  • 3
  • 13
  • 32
  • What is the goal of using a reliable dictionary inside a reliadble dictionary ? The "root" dictionary will make sure all items that are in the reliable dictionary are peristed as configured. That being said. `Dictionary` is not supported by the `DataContractSerializer` You could however use `IReliableDictionary>` – Preben Huybrechts Dec 16 '20 at 09:24
  • The idea is to have a better key-management by segregating certain categories thru dictionaries. – Sammy Dec 16 '20 at 13:54
  • @Sammy you could consider creating a composite key from both values and use that with a single reliable dictionary. – Oliver Dec 18 '20 at 21:29
  • If you have a limited number of static categories, you might also just consider having multiple ReliableDictionary states that you operate against instead of making a dictionary of dictionaries. – Whit Waldo Jun 07 '21 at 19:46

0 Answers0