Required properties causes error
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.7k
- Forks
- 313
- PR merge metrics
- No merged PRs in 30d
Description
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();
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example and inspect MyClass.MemoryPackFormatter.g.cs, focusing on the Deserialize method and the shown new MyClass() construction. Trace which generator entry point emits that code, then verify that the generated formatter compiles for a required property and deserialization completes without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100