Skip to content

RedisOutputCacheProvider Serialization broke in version 4.0.1 #221

Open
@DaveSweeton

Description

@DaveSweeton

We recently updated from version 3.0.1 to version 4.0.1 and output caching broke silently.

After investigating, the issue seems to be in serialization. 3.0.1 used this for serialization:

redisUtility.GetBytesFromObject(entry), which used a custom or BinarySerializer.

In 4.0,1 the code switched to:

System.Web.OutputCache.Serialize(ms, outputCacheEntry);

The problem with using that method is that it whitelists object types that it supports, it is not a general serialization method:

public static void Serialize(Stream stream, object data)
{
  BinaryFormatter binaryFormatter = new BinaryFormatter();
  switch (data)
  {
    case OutputCacheEntry _:
    case PartialCachingCacheEntry _:
    case CachedVary _:
    case ControlCachedVary _:
    case FileResponseElement _:
    case MemoryResponseElement _:
    case SubstitutionResponseElement _:
      binaryFormatter.Serialize(stream, data);
      break;
    default:
      throw new ArgumentException(System.Web.SR.GetString("OutputCacheExtensibility_CantSerializeDeserializeType"));
  }
}

System.Web.Caching.CachedVary is in the allowed list, but Microsoft.AspNet.OutputCache.CachedVary is not (since it's not a dependency).

This means that RedisOutputCacheProvider does not work with Microsoft.AspNet.OutputCache.OutputCacheModuleAsync, which seems like a common use case.

Switching back to internal serialization would fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions