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
when app restart, L1 Cache(memory Cache) invalid, get data from L2 Cache, throw this bug .
[09:52:24 ERR] An unhandled exception has occurred while executing the request.
System.InvalidCastException: Unable to cast object of type 'System.Text.Json.JsonElement' to type 'xx.Ai.AudioMergeInfo'.
at ZiggyCreatures.Caching.Fusion.Internals.Memory.FusionCacheMemoryEntry`1.GetValueTValue1 in //src/ZiggyCreatures.FusionCache/Internals/Memory/FusionCacheMemoryEntry.cs:line 68
at ZiggyCreatures.Caching.Fusion.FusionCache.GetValueFromMemoryEntry[TValue](String operationId, String key, IFusionCacheMemoryEntry entry, FusionCacheEntryOptions options) in //src/ZiggyCreatures.FusionCache/FusionCache.cs:line 1000
at ZiggyCreatures.Caching.Fusion.FusionCache.TryGet[TValue](String key, FusionCacheEntryOptions options, CancellationToken token) in /_/src/ZiggyCreatures.FusionCache/FusionCache_Sync.cs:line 602
at xx.Ai.Cache.HybridCache.TryGet[T](String key, T& value) in E:\Work\xx\xx\xx.Ai\xx.Ai.Common\Cache\HybridCache.cs:line 66
this bug on
ZiggyCreatures.FusionCache.Serialization.SystemTextJson, throw System.Text.Json.JsonElement to TValue error
and
ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson, throw Newtonsoft.Json.Linq.JObject to TValue error
Related to ZiggyCreatures#386
Fix deserialization issue when retrieving data from L2 Cache after an app restart.
* **FusionCacheMemoryEntry.cs**
- Update `GetValue<TValue1>` method to handle deserialization correctly for `JsonElement` and `JToken`.
- Add checks to determine if the value is of type `JsonElement` or `JToken`.
- Use the appropriate deserializer to convert `JsonElement` or `JToken` to `TValue1`.
* **FusionCacheNewtonsoftJsonSerializer.cs**
- Update `Deserialize<T>` method to handle conversion correctly for `JToken`.
- Add a check to determine if the data is of type `JToken`.
- Use the appropriate deserializer to convert `JToken` to `T`.
* **FusionCacheSystemTextJsonSerializer.cs**
- Update `Deserialize<T>` method to handle conversion correctly for `JsonElement`.
- Add a check to determine if the data is of type `JsonElement`.
- Use the appropriate deserializer to convert `JsonElement` to `T`.
* **SerializationTests.cs**
- Add tests to ensure deserialization works correctly after an app restart.
- Create a test case for `FusionCacheNewtonsoftJsonSerializer`.
- Create a test case for `FusionCacheSystemTextJsonSerializer`.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ZiggyCreatures/FusionCache/issues/386?shareId=XXXX-XXXX-XXXX-XXXX).
Hi @gmij , by a first look it seems like you have saved the value with a certain type and are trying to get it with a different type, but I can't understand more with the info provided.
Can you please provide an MRE, maybe via a GIST or similar?
Describe the bug
when app restart, L1 Cache(memory Cache) invalid, get data from L2 Cache, throw this bug .
[09:52:24 ERR] An unhandled exception has occurred while executing the request.
System.InvalidCastException: Unable to cast object of type 'System.Text.Json.JsonElement' to type 'xx.Ai.AudioMergeInfo'.
at ZiggyCreatures.Caching.Fusion.Internals.Memory.FusionCacheMemoryEntry`1.GetValueTValue1 in //src/ZiggyCreatures.FusionCache/Internals/Memory/FusionCacheMemoryEntry.cs:line 68
at ZiggyCreatures.Caching.Fusion.FusionCache.GetValueFromMemoryEntry[TValue](String operationId, String key, IFusionCacheMemoryEntry entry, FusionCacheEntryOptions options) in //src/ZiggyCreatures.FusionCache/FusionCache.cs:line 1000
at ZiggyCreatures.Caching.Fusion.FusionCache.TryGet[TValue](String key, FusionCacheEntryOptions options, CancellationToken token) in /_/src/ZiggyCreatures.FusionCache/FusionCache_Sync.cs:line 602
at xx.Ai.Cache.HybridCache.TryGet[T](String key, T& value) in E:\Work\xx\xx\xx.Ai\xx.Ai.Common\Cache\HybridCache.cs:line 66
this bug on
ZiggyCreatures.FusionCache.Serialization.SystemTextJson, throw System.Text.Json.JsonElement to TValue error
and
ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson, throw Newtonsoft.Json.Linq.JObject to TValue error
version : v2.1.0
To Reproduce
Here's a MRE (Minimal Reproducible Example) of the issue:
Expected behavior
Deserialize the JsonData to TValue.
Versions
I've encountered this issue on:
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: