Skip to content

Required properties causes error #437

Description

@AdamJachocki

Hi, when I have a class like:

[MemoryPackable(GenerateType.CircularReference)]
public partial class MyClass
{
    [MemoryPackOrder(0)]
    public MyOtherClass? Parent { get; set; }

    [MemoryPackOrder(1)]
    public required string Key {get; set;} = string.Empty;
}

It gives me an error:
Required member 'MyClass.Key' must be set in the object initializer or attribute constructor.

The error is inside generated file: MyClass.MemoryPackFormatter.g.cs inside Deserialize method:

if (value == null)
{
    value = new MyClass();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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