Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distributed Caching - V15.0.0-alpha3 #265

Closed
johnhydemtm365 opened this issue Feb 5, 2021 · 7 comments
Closed

Distributed Caching - V15.0.0-alpha3 #265

johnhydemtm365 opened this issue Feb 5, 2021 · 7 comments
Assignees
Labels

Comments

@johnhydemtm365
Copy link
Contributor

johnhydemtm365 commented Feb 5, 2021

Brief bug description

Error deserializing rich text content when using distributed caching
JsonSerializationException: Cannot preserve reference to array or readonly list, or list created from a non-default constructor: Kentico.Kontent.Delivery.ContentItems.RichText.RichTextContent. Path 'Item.Articles.$values[0].BodyCopy.$values'.

This happens on both my current project and also the Dancing Goat project when using 15.0.0-alpha3 of the delivery client

Kentico.Kontent.Delivery 15.0.0-alpha3
Kentico.Kontent.Delivery.Caching 15.0.0-alpha3
Kentico.Kontent.Delivery.Abstractions 15.0.0-alpha3

What went wrong?

Repro steps

Download dancing goat project, configure distributed caching
Set the caching to 30 seconds
Load the site
Refresh the page immediately

Expected behavior

Page refreshes using the cached version

Additional context

Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, object existingValue, string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadMetadataProperties(JsonReader reader, ref Type objectType, ref JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue, out object newValue, out string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, object target)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, object existingValue, string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadMetadataProperties(JsonReader reader, ref Type objectType, ref JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue, out object newValue, out string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, object target)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor creator, string id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, string id, out bool createdFromNonDefaultCreator)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, bool checkAdditionalContent)
Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader)
Kentico.Kontent.Delivery.Caching.Extensions.SerializationExtensions.FromBson(byte[] byteArray)
Kentico.Kontent.Delivery.Caching.DistributedCacheManager.TryGetAsync(string key)
Kentico.Kontent.Delivery.Caching.DistributedCacheManager.GetOrAddAsync(string key, Func<Task> valueFactory, Func<T, bool> shouldCache, Func<T, IEnumerable> dependenciesFactory)
Kentico.Kontent.Delivery.Caching.DeliveryClientCache.GetItemAsync(string codename, IEnumerable parameters)
DancingGoat.Controllers.HomeController.Index() in HomeController.cs

 var response = await _client.GetItemAsync<Home>("home", new LanguageParameter(Language), new DepthParameter(1));

@petrsvihlik
Copy link
Contributor

I was able to reproduce it.

So far, I can see that this scenario is not covered with tests because the tests use string-based rich-text resolution.

https://github.com/Kentico/kontent-delivery-sdk-net/blob/c136595e678d65673e9dc1834ae063fef0f2a8d7/Kentico.Kontent.Delivery.Caching.Tests/ContentTypes/Article.Generated.cs#L38

So first, we need to replicate the error with a test and then fix it.

My wild guess is that classes such as RichTextContent, and implementations of IRichTextBlock should be enriched with [JsonConstructor]... let's see

@petrsvihlik
Copy link
Contributor

BTW - I hope we'll solve the dichotomy of rich text rendering once and for all in the v16 milestone. Here's the proposal: #259

petrsvihlik added a commit to kontent-ai/sample-app-net that referenced this issue Feb 7, 2021
@petrsvihlik
Copy link
Contributor

@petrsvihlik petrsvihlik self-assigned this Feb 7, 2021
@petrsvihlik petrsvihlik added the bug label Feb 7, 2021
@petrsvihlik petrsvihlik added this to the v15 - "named clients" milestone Feb 7, 2021
@petrsvihlik
Copy link
Contributor

https://github.com/Kentico/kontent-delivery-sdk-net/releases/tag/15.0.0-alpha4

seems to be working.

thanks for testing the distributed caching!

@johnhydemtm365
Copy link
Contributor Author

johnhydemtm365 commented Feb 8, 2021 via email

@petrsvihlik
Copy link
Contributor

Yes, there was a breaking change to make the code simpler. Please refer to: https://github.com/Kentico/kontent-sample-app-net/compare/RTE-problem

The Blocks property was just a wrapper around an IEnumerable aspect of the IRichTextContent itself. You can safely remove the Blocks property and use the object itself.

@johnhydemtm365
Copy link
Contributor Author

johnhydemtm365 commented Feb 8, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants