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
Private fields on base class do not get serialized #1756
Comments
If you want private fields to be serialized, you need to use the AllowPrivate variant of the resolver. |
it doesn't work too. DerivedFromBase message = new DerivedFromBase();
message.Add(0);
var bytes = MessagePackSerializer.Serialize(message, ContractlessStandardResolverAllowPrivate.Options);
var deserialized = MessagePackSerializer.Deserialize<DerivedFromBase>(bytes, ContractlessStandardResolverAllowPrivate.Options);
class DerivedFromBase : Base { }
class Base
{
private readonly List<int> _itmes;
public Base()
{
_itmes = new();
}
public void Add(int value)
{
_itmes.Add(value);
}
} But if we serialize the base class, everything works fine. Base message = new Base();
message.Add(0);
var bytes = MessagePackSerializer.Serialize(message, TypelessContractlessStandardResolver.Options);
var deserialized = MessagePackSerializer.Deserialize<Base>(bytes, TypelessContractlessStandardResolver.Options); In this case, |
Thank you for trying that out. Sounds like a bug. Albeit, IMO the contractless resolver does a poor job in general. It can't/shouldn't serialize all fields and all properties, because that would involve a lot of redundancy since properties are typically backed by fields. So I recommend (with or without this bug) that you apply the attributes if you own the type, or write a custom formatter if you don't. |
I also ran into the same Bug... |
Bug description
Private fields on base class do not get serialized
Repro steps
Expected behavior
field
_items
indeserialized
has 1 item.Actual behavior
field
_items
indeserialized
has 0 items.The text was updated successfully, but these errors were encountered: