Skip to content

Conversation

mgravell
Copy link
Contributor

@mgravell mgravell commented Mar 14, 2025

HybridCache uses System.Text.Json for the default serializer, which has some opinions on fields; this means that named-tuples (or value-tuples generally), and types that use value tuples or otherwise field-only values, can lose data.

We already detect value-tuples specifically as the root type, but real-world usage has highlit wider ranges of scenarios. This PR adds deeper detection for this scenario, applying the same workaround. It duly considers collection types and recursion scenarios.

fix dotnet/aspnetcore#60934

Microsoft Reviewers: Open in CodeFlow

@mgravell
Copy link
Contributor Author

mgravell commented Mar 14, 2025

Thought: we should explicitly restrict our override behaviour to scenarios that use the inbuilt STJ default options instance, not just ones that don't handle fields. If someone uses their own STJ options: we should respect it. The mechanism for people to do this is new and non-disclosed, so there is no issue changing that behaviour, i.e. right now the number of times anyone will have ever supplied a non-default STJ options is zero or a rounding error asymptotically approaching zero.

@mgravell mgravell force-pushed the marc/hc_json_deep branch from 4f5158f to b6e7a97 Compare March 18, 2025 12:21
@mgravell mgravell requested a review from DeagleGross March 18, 2025 12:43
@mgravell mgravell merged commit 354bf8d into dotnet:main Mar 18, 2025
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hybrid Cache silently fails to correctly handle cached tuples
2 participants