You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A failed serialization makes StoreAsync overwrite the stored value with an empty file and report success #70
ISerializationProvider.Serialize discards the result of TrySerialize (Essentials/ISerializationProvider.cs, around lines 119–132):
publicstringSerialize(objectobj){usingStringWriterwriter=new();TrySerialize(obj,writer);// false is ignoredreturnwriter.ToString();// "" on failure}publicvoidSerialize(objectobj,TextWriterwriter)=>TrySerialize(obj,writer);
The file-based persistence providers write whatever SerializeAsync returns. That covers FileSystemPersistenceProvider.StoreAsync (around line 62) and TempPersistenceProvider.StoreAsync (around line 59). DataHome and ConfigHome delegate to FileSystem, so they are affected too.
Repro
Use TempPersistenceProvider<string> over JsonSerializationProvider:
StoreAsync("k", cyclic), where a node's Next points to itself. System.Text.Json throws JsonException, and TrySerialize returns false.
StoreAsync returns normally and ExistsAsync("k") is true, but RetrieveAsync("k") now returns null.
The previous good value has been replaced with an empty file and no error was raised. The same path is hit by any NotSupportedException from STJ (a System.Type property, for example), and by a YAML or TOML serializer failure.
Why it matters
A single unserializable value silently destroys the last good persisted state. The caller has no signal that anything went wrong. This is the kind of data loss a persistence layer exists to prevent.
Suggested fix
Make Serialize(object) and Serialize(object, TextWriter) throw InvalidOperationException when TrySerialize returns false. This matches how the other providers' non-Try methods behave, for example Encode, Hash and Decrypt.
StoreAsync's existing catch then wraps the failure in PersistenceProviderException before the file is touched, so the old value survives.
This changes the public behaviour of Serialize, so it likely needs a [minor] or [major] version tag.
Acceptance: a test stores a good value, then attempts to store an unserializable one. The second StoreAsync throws PersistenceProviderException, and RetrieveAsync still returns the good value.
Priority: High. Silent data loss in the persistence layer. One unserializable value replaces the last good stored value with an empty file, and StoreAsync reports success. This affects the FileSystem, Temp, DataHome and ConfigHome providers across every serializer.
Area / suggested assignment:ISerializationProvider.Serialize default implementations, and the file persistence providers' StoreAsync
Suggested next step: make the non-TrySerialize throw on false, as the issue proposes. Note that this changes public behaviour, so it needs a version tag.
Activity
matt-edmondson commentedon Sep 29, 2026
Triage
StoreAsyncreports success. This affects the FileSystem, Temp, DataHome and ConfigHome providers across every serializer.ISerializationProvider.Serializedefault implementations, and the file persistence providers'StoreAsyncSuggested next step: make the non-
TrySerializethrow onfalse, as the issue proposes. Note that this changes public behaviour, so it needs a version tag.Generated by Claude Code