user3953989
user3953989

Reputation: 1951

Getting error parsing ProtoBuf data

I'm serializing a linked list and when deserializing I get the following error.

Google.Protobuf.InvalidProtocolBufferException: 'Protocol message had too many levels of nesting. May be malicious. Use CodedInputStream.SetRecursionLimit() to increase the depth limit.'

I couldn't find a lot of documentation on how to fix this.

Upvotes: 1

Views: 1340

Answers (1)

Parrish Husband
Parrish Husband

Reputation: 3178

The recursion limit can be set by using CodedInputStream.CreateWithLimits:

public static CodedInputStream CreateWithLimits(Stream input, int sizeLimit, int recursionLimit)

Note the default recursion is a depth of 64. See the source here.

Edit: Can you post your model for your linked list items? You might be able to add in some flattening behavior before serialization is performed.

Upvotes: 1

Related Questions