Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: force-included properties without accessible setters are silently ignored #344

Open
MaxSavenkov opened this issue Oct 30, 2024 · 0 comments

Comments

@MaxSavenkov
Copy link

[MemoryPackable]
class A
{
    [MemoryPackInclude]
    public string SomeProperty { get; private set; }
}

When generating code for such class, MemoryPack will silently skip setting SomeProperty (but will generate code to write/read it), because it doesn't have accessible setter (because it will be unable to properly generate code for SET label, but since this is not a readonly field, it doesn't get passed to constructor, so both paths fail). This leads to many hours of debugging, because if you're adding attributes to existing fields, private, or omitted setters are easy to miss (doubly so, if you're doing it using some kind of automation in a big project).

I propose extending the check for readonly fields to properties that are marked with [MemoryPackInclude] attribute, because it explicitly tells the generator I want this property serialized. If it is absent, and the field is public, the situation becomes less clear, but maybe a warning would appropriate, too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant