Caching issue in development

Getting the following exception when trying to pull an object out of the cache, it was added fine

Exception has occurred: CLR/System.InvalidCastException
An exception of type 'System.InvalidCastException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Unable to cast object of type 'ᵀAɗƹϦŵɧҏҤũIԯŹӍijİαwʒԒȻҵʕɇԓӮťpǭԓͶӣӚЉҩԧđӓͲᴱ.ᵀrҪƆǺɸˋεӄԎΦǍаΚᴱ[System.Object]' to type 'ᵀAɗƹϦŵɧҏҤũIԯŹӍijİαwʒԒȻҵʕɇԓӮťpǭԓͶӣӚЉҩԧđӓͲᴱ.ᵀrҪƆǺɸˋεӄԎΦǍаΚᴱ[System.Nullable`1[FourRoads.VerintCommunity.ForumLastPost.Interfaces.LastReadPostInfo]]'.'
at System.Runtime.CompilerServices.CastHelpers.<IsInstanceOf_NoCacheLookup>g____PInvoke|4_0(Void* __toTypeHnd_native, Int32 __throwCastException_native, ObjectHandleOnStack __obj_native) at System.Runtime.CompilerServices.CastHelpers.<IsInstanceOf_NoCacheLookup>g____PInvoke|4_0(Void* __toTypeHnd_native, Int32 __throwCastException_native, ObjectHandleOnStack __obj_native) at System.Runtime.CompilerServices.CastHelpers.ChkCastAny_NoCacheLookup(Void* toTypeHnd, Object obj) at System.Runtime.CompilerServices.CastHelpers.ChkCast_Helper(Void* toTypeHnd, Object obj) at ᵀAɗƹϦŵɧҏҤũIԯŹӞŖѨћѤđΘɅιƚDŽċɘõãɔǷɦӡҲDZԦËϴЅʼnᴱ.ᵀĴǩӉVŹАζӓǼɞϬȾɧᴱ.Get[T](String key) at ᵀAɗƹϦŵɧҏҤũIԯŹӞŖѨћѤđΘɅιƚDŽċɘõãɔǷɦӡҲDZԦËϴЅʼnᴱ.ᵀÞҋĺòȐđçˬƁҩґԬʋᴱ.TryGet[T](String key, CacheScope scope, T& value, ConsistencyLevel consistency) at Telligent.Evolution.Extensibility.Caching.Version1.CacheService.TryGet[T](String key, CacheScope scope, T& value, GetOptions`1 options)

this is what it added to the cache

    public struct LastReadPostInfo
    {
        public int ReplyCount { get; set; }
        public Guid? ContentId { get; set; }
        public DateTime PostDate { get; set; }
    }
Parents
No Data
Reply Children
  • I've just implemented this and it is being called for every type in the system

    public
    class DistributedCacheSerializer<T> : IDistributedCacheSerializer<T>
        {
            public byte[] Serialize(T value)
            {
                return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value);
            }

            public T Deserialize(byte[] value)
            {
                return System.Text.Json.JsonSerializer.Deserialize<T>(value);
            }
        }
    Are you saying that for every entity we have defined in a project we will have to register a specific serializer?

    public class DistributedCacheSerializer : IDistributedCacheSerializer<RealType>
        {
            public byte[] Serialize(RealType value)
            {
                return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value);
            }

            public RealType Deserialize(byte[] value)
            {
                return System.Text.Json.JsonSerializer.Deserialize<RealType>(value);
            }
        }