What's wrong
PersistenceProviderUtilities.TryConvertToKey (Essentials/PersistenceProviderUtilities.cs ~L180) special-cases string, Guid and int, and otherwise uses Convert.ChangeType. That only works for IConvertible targets, so enum, TimeSpan, DateTimeOffset, Uri and similar types throw InvalidCastException. The broad catch turns that into false, and the key is silently dropped from GetAllKeysAsync.
Repro
var p = new FileSystemPersistenceProvider<Color>(new NativeFileSystemProvider(), new JsonSerializationProvider(), dir);
await p.StoreAsync(Color.Red, new Settings());
Observed:
enum key: Exists(Red)=True keys=[] files=[Red.json]
TimeSpan key: keys=[]
DateTimeOffset key: keys=[]
Expected: [Red], [00:05:00] and the stored DateTimeOffset. InMemoryPersistenceProvider returns them.
Why it matters
Anything that enumerates keys to list, migrate, export or selectively clear never sees these entries, with no error. Enum keys in particular are a natural choice for a fixed set of persisted slots.
Suggested fix
- For enums, use
Enum.TryParse(typeof(TKey), value, ignoreCase: false, out object? result).
- More generally, use
TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(value), which covers TimeSpan, DateTimeOffset, Uri, etc.
Ideally, fix this together with #46 (culture-dependent key formatting), so keys are formatted and parsed through one invariant helper.
What's wrong
PersistenceProviderUtilities.TryConvertToKey(Essentials/PersistenceProviderUtilities.cs~L180) special-casesstring,Guidandint, and otherwise usesConvert.ChangeType. That only works forIConvertibletargets, so enum,TimeSpan,DateTimeOffset,Uriand similar types throwInvalidCastException. The broad catch turns that intofalse, and the key is silently dropped fromGetAllKeysAsync.Repro
Observed:
Expected:
[Red],[00:05:00]and the storedDateTimeOffset.InMemoryPersistenceProviderreturns them.Why it matters
Anything that enumerates keys to list, migrate, export or selectively clear never sees these entries, with no error. Enum keys in particular are a natural choice for a fixed set of persisted slots.
Suggested fix
Enum.TryParse(typeof(TKey), value, ignoreCase: false, out object? result).TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(value), which coversTimeSpan,DateTimeOffset,Uri, etc.Ideally, fix this together with #46 (culture-dependent key formatting), so keys are formatted and parsed through one invariant helper.