Skip to content

Missing MsgPack003 error when using class from other project #2233

@treziac

Description

@treziac

Bug description

When a class annotated with MessagePackObject define a property with a type defined in another project, this type is not checked to be properly annotated with MessagePackObject.

Repro steps

Create a first csproj, with a class without attributes

    public class Foo
    {
        public required int Id { get; init; }
    }

Create a second project in the same solution, referencing the first one, with in it

public class Program
{
    public static void Main()
    {
        MessagePackSerializer.Serialize(new Bar());
    }
}

[MessagePackObject]
public class Bar
{
    public Bar()
    {
        Foo = new Foo { Id = 1 };
    }

    [Key(0)]
    public Foo Foo { get; set; }
}

Expected behavior

A compilation error with MsgPack003 should be raised

Actual behavior

Code compiles, and an exception MessagePack.FormatterNotRegisteredException: SharedData.Foo is not registered in resolver: MessagePack.Resolvers.StandardResolver is thrown at runtime

  • Version used: 3.1.4 and master
  • Runtime: tested on .NET Core 9 & net472

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions