ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.74k stars 92 forks source link

[BUG] Can't instantiate MemoryPack serializer on NET7 #93

Closed RMcD closed 1 year ago

RMcD commented 1 year ago

Describe the bug Trying to instantiate the FusionCacheCysharpMemoryPackSerializer on .NET7 throws a runtime exception.

Method 'Serialize' on type 'ZiggyCreatures.Caching.Fusion.Serialization.CysharpMemoryPack.Internals.FusionCacheDistributedEntryFormatter`1' from assembly 'ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack, Version=0.17.0.0, Culture=neutral, PublicKeyToken=null' tried to implicitly override a method with weaker type parameter constraints.

To Reproduce Here's a MRE (Minimal Reproducible Example) of the issue:

// When using .NET7 runtime target.
var _ = new FusionCacheCysharpMemoryPackSerializer();

LinqPad

<Query Kind="Statements">
  <NuGetReference>ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack</NuGetReference>
  <Namespace>ZiggyCreatures.Caching.Fusion</Namespace>
  <Namespace>ZiggyCreatures.Caching.Fusion.Serialization</Namespace>
  <Namespace>ZiggyCreatures.Caching.Fusion.Serialization.CysharpMemoryPack</Namespace>
  <RuntimeVersion>7.0</RuntimeVersion>
</Query>

var _ = new FusionCacheCysharpMemoryPackSerializer();

Expected behavior The serializer should instantiate the object like it does on .NET6/netstandard2.1

Versions I've encountered this issue on:

Additional context Add any other context about the problem here.

jodydonetti commented 1 year ago

Hi @RMcD and thanks for using FusionCache. Will check and let you know.

jodydonetti commented 1 year ago

I can confirm the same problem, and I think I know what is happening here: to be sure though, I have to summon MemoryPack's creator.

I created an issue there, let's see what @neuecc will say.

jodydonetti commented 1 year ago

Hi @RMcD , an update on this: my guess was in fact correct, and you can see the details of the discussion in the issue I linked.

Long story short: I don't know what will happen regarding MemoryPack itself, if it will make some changes to have a more standard experience regarding transitive .NET version dependencies or not. In the meantime though, I tried a different approach for my library (thanks to some suggestions from its author, which is super kind and helpful 🙏) and after some tweaks I made it to work well, and all the 300+ tests are now passing. So now I'm preparing a new version which should fix this specific issue: I will release it soon, but I don't know if I will be able to do it today or later. Will update you.

Oh, and thanks for your tip, which started the conversation!

jodydonetti commented 1 year ago

FYI: I just pushed the new branch

jodydonetti commented 1 year ago

Hi @RMcD , just wanted to update you: the code has been updated and it's now working correctly also on .NET 7, and thanks to some back & forth with MemoryPack author it's now in perfect shape.

I'll release a new version very soon.

jodydonetti commented 1 year ago

Hi @RMcD , the new v0.18.0 has been released 🎉

It includes the needed changes, too.

Please let me know if everything is fine.