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
Fix handling of readonly private fields #1267
Conversation
Disallow writing to readonly private fields even when using a resolver that allows using private fields. Fixes: MessagePack-CSharp#1218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks.
@neuecc Any concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks!
This regressed #1308. I'm looking for a mutually acceptable solution. |
This change unfortunately broke deserializing for many of our objects. Is there any way to restore the ability to set the values of readonly fields without having to create custom constructors for each object? For example, this is what an object might look like:
Before MessagePack 2.3.75 this worked, but after 2.3.75 the Code field is always empty after deserializing. What is the best way to get this working again? Thanks! |
IMHO; this shouldn't work. I expect serializer libraries to maintain the "readonly" constraints set by the compiler. The fact that message-pack was writing to readonly fields came as a big surprise to me. Also, @RobotGizmo, how on earth is that |
I think our issue is that we view the serializer as something that dumps the data from an object then puts it back in blindly. If there is a field with data it should be filled in again unless it's marked with The example above was just a part of the code as a sample, we do have a public constructor as well, like this:
|
@RobotGizmo #1314 already corrected the regression. Can you confirm? |
@AArnott Thanks, it looks like it's working as it did before with v2.3.85. :) |
Disallow writing to readonly private fields even when using a resolver
that allows using private fields.
Fixes: #1218