问题
[Required]
[DefaultValue(-1)]
public int MvcUserId { get; set; }
when I set MvcUserId =-1; but I will get MvcUserId =0; if i use json serlize the object ,everything will be ok.
回答1:
You need to actually apply the default:
[Required]
[DefaultValue(-1)]
public int MvcUserId { get; set; } = -1;
Without that protobuf-net ignores the value on send (because it is the default), and on receive there is nothing to process. protobuf-net assumes that your code correctly applies the defaults.
来源:https://stackoverflow.com/questions/41692470/protobuf-net-cant-send-negative-number