When a [MessagePackObject]-attributed type cannot be serialized without access to non-public members, the AllowPrivate property should be set on the MessagePackObjectAttribute so that:
- Dynamically generated formatters can serialize the type, even if
DynamicObjectResolveris used instead ofDynamicObjectResolverAllowPrivate. - Analyzers can help ensure proper annotation of non-public members.
[MessagePackObject]
public class MyData {
[Key(0)]
internal int Foo { get; set; }
}[MessagePackObject]
internal class MyData {
[Key(0)]
public int Foo { get; set; }
}Simply add the AllowPrivate = true syntax to the [MessagePackObject] attribute:
[MessagePackObject(AllowPrivate = true)]
internal class MyData {
[Key(0)]
internal int Foo { get; set; }
}An automated code fix is offered for this diagnostic.