Skip to content

MessagePack 3.1 doesn't create formatters for abstract base classes unless they include MessagePackObjectAttribute #2219

@abond-sd

Description

@abond-sd

Bug description

In v2, [MessagePackObject] wasn't required for code generation to be able to serialize and deserialize the base type.
In v3, a field or property which includes [Union] but does not include [MessagePackObject] will not be serialized or deserialized in an AOT-compiled build; a MessagePack.FormatterNotRegisteredException is thrown indicating that the base type is not recognized.

Repro steps

  1. Create a new Unity project with MessagePack v3
  2. Configure the project to use IL2CPP
  3. Create an abstract base class with a [Union] attribute
  4. Instantiate a derived instance of that type at runtime.
  5. Serialize and deserialize it using an abstract reference.
  6. --> FormatterNotRegisteredException is thrown

Expected behavior

Either an analyzer should indicate that [MessagePackObject] is required on the abstract base class, or the attribute should not be necessary (similar to it not being needed for interfaces).

Actual behavior

A MessagePack.FormatterNotRegisteredException was thrown when attempting to serialize or deserialize an field or property of the abstract type.

  • Version used: 3.1.4
  • Runtime: Unity IL2CPP

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions