Skip to content

Fix resolution of registered generic collection formatters - #464

Open
dajiaohuang wants to merge 1 commit into
Cysharp:mainfrom
dajiaohuang:fix/generic-collection-registration-20261015
Open

dajiaohuang wants to merge 1 commit into
Cysharp:mainfrom
dajiaohuang:fix/generic-collection-registration-20261015

Conversation

@dajiaohuang

Copy link
Copy Markdown

Problem

The public RegisterCollection(Type), RegisterSet(Type) and RegisterDictionary(Type) overloads accept open generic collection definitions, but serializing a closed instance still throws MemoryPackSerializationException saying it is not registered. For example:

public class CustomList<T> : List<T> { }

MemoryPackFormatterProvider.RegisterCollection(typeof(CustomList<>));
var bytes = MemoryPackSerializer.Serialize(new CustomList<int> { 1, 2, 3 });

Registration stores the open generic definition as the key, while resolution looks up the constructed type. The formatter construction also needs the constructed type's actual generic arguments, not the definition's unbound parameters.

Change

Look up the generic definition and close the formatter with the collection type and its actual generic arguments. No wire-format or public API change.

Add public serialize/deserialize regression tests for all three registration overloads, covering both generic and runtime-Type APIs and nullable collection elements/dictionary values.

Validation

  • The three regression tests fail on main f96ba3054f14e528b5f75eba4ff02de0b71fa64a with the not-registered exception and pass with the fix.
  • Release solution build and pack pass (existing warnings remain).
  • Windows x64, .NET 8 runtime / .NET SDK 10.0.100. Unity/IL2CPP and NativeAOT runtime checks were not run.

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

Successfully merging this pull request may close these issues.

1 participant