Getting the following exception when trying to pull an object out of the cache, it was added fine
this is what it added to the cache
Getting the following exception when trying to pull an object out of the cache, it was added fine
You are right, I assume as it's a struct it is boxing it and then it breaks
public void Insert(string key, object value, string[] tags, TimeSpan timeout)
{
CacheService.Put(key, CacheScope.All, value, new PutOptions
{
ExpiresAfter = timeout,
Tags = tags ?? Array.Empty<string>()
});
}
Tell me more about IDistributedCacheSerializationProvider and it's intent?
Correct. You'd want to use this generic version instead which doesn't box it as an object.
public void Insert<T>(string key, T value, string[] tags, TimeSpan timeout)
{
CacheService.Put(key, CacheScope.All, value, new PutOptions
{
ExpiresAfter = timeout,
Tags = tags ?? Array.Empty<string>()
});
}Tell me more about IDistributedCacheSerializationProvider and it's intent?
Previous versions of caching relied on .NET's binary formatting when serializing/deserializing objects for the distributed cache. Binary formatting was removed as of .NET 9 due to security concerns.

The typical workaround is to use an explicit serialization format instead, JSON, MessagePack, etc.
IDistributedCacheSerializationProvider is a way for a plugin to define how a custom type can be serialized to and from a byte array, and the caching service looks for one if it's asked to serialize a type it doesn't know about for the distributed cache.
It's not required if only caching in-process, since those are just live, non-serialized, objects.