Skip to content

Custom IMessagePackFormatter for Silk.NET's vector types result in compilation failure and Visual Studio crashes #2154

Description

@CptWesley

Bug description

Attempting to create custom IMessagePackFormatter for [Silk.NET]'s vector type results in compilation failure and Visual Studio 2022 crashing.

Repro steps

  • Create new net8.0 console project
  • Include MessagePack version 3.1.3
  • Include Silk.NET.Maths version 2.22.0
  • Define type:
public sealed partial class Vector3DFormatter : IMessagePackFormatter<Vector3D<float>>
{
    public Vector3D<float> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
    {
        var x = reader.ReadSingle();
        var y = reader.ReadSingle();
        var z = reader.ReadSingle();
        return new(x, y, z);
    }

    public void Serialize(ref MessagePackWriter writer, Vector3D<float> value, MessagePackSerializerOptions options)
    {
        writer.Write(value.X);
        writer.Write(value.Y);
        writer.Write(value.Z);
    }
}
  • Add assembly attribute:
[assembly: MessagePack.MessagePackKnownFormatter(typeof(Vec3Formatter))]
  • Try define MessagePack Object:
[MessagePackObject]
public sealed record Foo
{
    [Key(0)]
    public required Vec3<float> Position { get; init; }
}

Expected behavior

No errors/crashes.

Actual behavior

Visual Studio stops responding after a few seconds, before restarting itself (sometimes after all features disable themselves).
When building the project using dotnet build, the compilation fails.

  • Version used: 3.1.3
  • Runtime: net8.0

Additional context

Copying the source code of Vector3D<T> into the local project and using that version has the same results. I am currently trying to find the exact part of the type definition that results in this behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions