Skip to content

Protobuf-net.Grpc fails when using protobuf-net 3.0 alpha #100

@RichardVogelij

Description

@RichardVogelij

Hi, when I try to send over a slightly complex object which uses ProtoInclude (which works fine on protobuf-net 2.*) it fails in 3.0-alpha when I update protobuf-net.grpc from 1.0.81 to 1.0.90.

So in essence: this issue rises when using protobuf.net 3.0+ and protobuf-net.grpc 1.0.90 (not on 1.0.81)

There are no issues when I serialize/deserialize/deepclone my object in protobuf-net-3.0.0-alpha - but protobuf-net.grpc fails server side in protobuf-net.grpc.

This is the object in which this issue is reproduced.

[ProtoContract]
public class TestObject
{
	[ProtoMember(1)]
	public TestThingy Test {get;set;}
}

[ProtoContract]
[ProtoInclude(1, typeof(TestThingy))]
public abstract class TestBase
{
	[ProtoMember(2)]
	public string SomeText { get; set; }

	public abstract string SomeText2 { get; set; }
}

[ProtoContract]
public class TestThingy : TestBase
{
	[ProtoMember(1)]
	public override string SomeText2 { get; set; }
}

public interface ITest { ValueTask<TestObject> GetTestInstance(); }

As soon as my server-side implementation of ITest returns the TestObject i get:

Length mismatch; calculated '18', actual '8'


   at ProtoBuf.Internal.ThrowHelper.ThrowInvalidOperationException(String message, Exception innerException) in /_/src/protobuf-net.Core/Internal/ThrowHelper.cs:line 56
   at ProtoBuf.ProtoWriter.BufferWriterProtoWriter.WriteWithLengthPrefix[T](State& state, T value, ISubTypeSerializer`1 serializer) in /_/src/protobuf-net.Core/ProtoWriter.BufferWriter.cs:line 288
   at ProtoBuf.ProtoWriter.BufferWriterProtoWriter.WriteWithLengthPrefix[T](State& state, T value, ISerializer`1 serializer, PrefixStyle style) in /_/src/protobuf-net.Core/ProtoWriter.BufferWriter.cs:line 260
   at ProtoBuf.ProtoWriter.BufferWriterProtoWriter.WriteMessage[T](State& state, T value, ISerializer`1 serializer, PrefixStyle style, Boolean recursionCheck) in /_/src/protobuf-net.Core/ProtoWriter.BufferWriter.cs:line 209
   at ProtoBuf.ProtoWriter.State.WriteMessage[T](Int32 fieldNumber, SerializerFeatures features, T value, ISerializer`1 serializer) in /_/src/protobuf-net.Core/ProtoWriter.State.WriteMethods.cs:line 335
   at ProtoBuf.ProtoWriter.State.SerializeRoot[T](T value, ISerializer`1 serializer) in /_/src/protobuf-net.Core/ProtoWriter.State.WriteMethods.cs:line 542
   at ProtoBuf.MeasureState`1.SerializeCore(State state) in /_/src/protobuf-net.Core/MeasureState.cs:line 86
   at ProtoBuf.MeasureState`1.Serialize(IBufferWriter`1 writer) in /_/src/protobuf-net.Core/MeasureState.cs:line 106
   at ProtoBuf.Meta.TypeModel.ProtoBuf.IMeasuredProtoOutput<System.Buffers.IBufferWriter<System.Byte>>.Serialize[T](MeasureState`1 measured, IBufferWriter`1 destination) in /_/src/protobuf-net.Core/Meta/TypeModel.InputOutput.cs:line 47
   at ProtoBuf.Grpc.Configuration.ProtoBufMarshallerFactory.ContextualSerialize[T](T value, SerializationContext context) in ~\protobuf-src\protobuf-net.Grpc\src\protobuf-net.Grpc\Configuration\ProtoBufMarshallerFactory.cs:line 129
   at Grpc.Core.Internal.AsyncCallBase`2.UnsafeSerialize(TWrite msg, DefaultSerializationContext context)
   at Grpc.Core.Internal.AsyncCallServer`2.SendStatusFromServerAsync(Status status, Metadata trailers, Nullable`1 optionalWrite)
   at Grpc.Core.Internal.UnaryServerCallHandler`2.<HandleCall>d__4.MoveNext()

I attempted to use protobuf-net 3.0 in my project because it seems to be the only version that does not give all sorts of trouble regarding the dependency on System.Reflection.Emit in 2.0 which is not possible in a Xamarin ios project.

This issue started to appear when I updated protobuf-net.grpc from 1.0.81 to 1.0.90 - I already was running protobuf.net in 3.0 space some time.

I am fairly certain the bug is actually in protobuf-net 3.0.alpha - but since updating protobuf-grpc.net to the latest version started to cause this issue I felt i should create the issue here.

Thank you for the great work on protobuf-net.*!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions