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

RedisOutputCacheProvider Serialization broke in version 4.0.1 #221

Open
DaveSweeton opened this issue Jan 19, 2024 · 0 comments
Open

RedisOutputCacheProvider Serialization broke in version 4.0.1 #221

DaveSweeton opened this issue Jan 19, 2024 · 0 comments

Comments

@DaveSweeton
Copy link

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.

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

No branches or pull requests

1 participant