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
  • This points to a mismatch in the type of object being added to cache vs how it's being gotten from cache. The cache methods are strongly typed now, relying on generic methods for ensuring the same type is added/pulled from cache.

     

    This service is available via Telligent.Evolution.Extensibility.Caching.Version1.CacheService Properties Name Type Description Default Options PermissionsKey string Methods T Get<T>( string key, CacheScope…
    Last edited in Verint Community 14.x > API Documentation

    In particular:

    // given an object of type nullable LastReadPostInfo...
    FourRoads.VerintCommunity.ForumLastPost.Interfaces.LastReadPostInfo? lastReadPostInfo = null;
    Telligent.Evolution.Extensibility.Caching.Version1.CacheService.Put("my-key", CacheScope.Process, lastReadPostInfo); ;
    
    // Retrieve from cache with same nullable type
    if (Telligent.Evolution.Extensibility.Caching.Version1.CacheService.TryGet<FourRoads.VerintCommunity.ForumLastPost.Interfaces.LastReadPostInfo?>("my-key", CacheScope.Process, out var cachedLastReadPostInfo))
    {
        // do something with cachedLastReadPostInfo
    }

Reply
  • This points to a mismatch in the type of object being added to cache vs how it's being gotten from cache. The cache methods are strongly typed now, relying on generic methods for ensuring the same type is added/pulled from cache.

     

    This service is available via Telligent.Evolution.Extensibility.Caching.Version1.CacheService Properties Name Type Description Default Options PermissionsKey string Methods T Get<T>( string key, CacheScope…
    Last edited in Verint Community 14.x > API Documentation

    In particular:

    // given an object of type nullable LastReadPostInfo...
    FourRoads.VerintCommunity.ForumLastPost.Interfaces.LastReadPostInfo? lastReadPostInfo = null;
    Telligent.Evolution.Extensibility.Caching.Version1.CacheService.Put("my-key", CacheScope.Process, lastReadPostInfo); ;
    
    // Retrieve from cache with same nullable type
    if (Telligent.Evolution.Extensibility.Caching.Version1.CacheService.TryGet<FourRoads.VerintCommunity.ForumLastPost.Interfaces.LastReadPostInfo?>("my-key", CacheScope.Process, out var cachedLastReadPostInfo))
    {
        // do something with cachedLastReadPostInfo
    }

Children