Open GoogleCodeExporter opened 9 years ago
I've looked into this further today and found a possible fix for the issue.
Initially the TestWcfServer project did not have ProtoEndpointBehavior attached
to the server (as this is commented out in the web.config). After putting this
back and rerunning the test project, an "Invalid wire-type" exception is thrown
as with my main project.
Debugging into the protobuf.net code I found that an assertion fails on this
line in the Read method of TagDecorator.cs
Helpers.DebugAssert(fieldNumber == source.FieldNumber);
Here fieldNumber is 1 and source.FieldNumber is 0.
Tracing back through the call stack to ReadObject method of the
XmlProtoSerializer I find the following code:
if (isList)
{
result = model.Deserialize(ms, null, type, null);
}
else
{
using (ProtoReader protoReader = new ProtoReader(ms, model, null))
{
result = model.Deserialize(key, null, protoReader);
}
}
which deserialises the stream differently for list types.
If I add the following clause to the if statement so that enums are
deserialised as lists then the issue seems to be fixed
if (isList || type.IsEnum)
Please look into this and check that this doesn't have any side effects. You
can test the behaviour using the code sample the issue description above.
Thanks
Dave Sparks
Original comment by dsparkp...@gmail.com
on 1 Aug 2012 at 2:21
This is possibly related to issue 266
Original comment by dsparkp...@gmail.com
on 1 Aug 2012 at 2:29
will need to investigate before concluding too much, but thanks for your description - I have a full repro now (the first passes, the second fails as you describe) - I will look as soon as I can:
public enum Foo
{
A,
B,
C
}
[ProtoContract]
public class FooWrapper
{
[ProtoMember(1)]
public Foo Foo { get; set; }
}
[Test]
public void TestRoundTripWrappedEnum()
{
var ser = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(FooWrapper));
var ms = new MemoryStream();
ser.WriteObject(ms, new FooWrapper { Foo = Foo.B });
ms.Position = 0;
var clone = (FooWrapper)ser.ReadObject(ms);
Assert.AreEqual(Foo.B, clone.Foo);
}
[Test]
public void TestRoundTripNakedEnum()
{
var ser = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof (Foo));
var ms = new MemoryStream();
ser.WriteObject(ms, Foo.B);
ms.Position = 0;
var clone = (Foo)ser.ReadObject(ms);
Assert.AreEqual(Foo.B, clone);
}
Original comment by marc.gravell
on 1 Aug 2012 at 6:42
Hi,
The same problem happened to me today.
The quick fix of special-casing enums like in Comment 1 works but I don't
really want to go in production with a hack on some code I don't fully
understand.
Do you plan on looking into this soon or should I look deeper and try to solve
it ?
For now I don't really understand the serialization process, specifically why
TagDecorator is writing a type header in Write but expecting the type header to
have already been readed in Read (Doesn't work in this case as the reader is
still in a not-initialized state).
Thanks.
Original comment by virtualb...@gmail.com
on 6 Nov 2012 at 8:55
Hi,
same problem occurs, if you simply use a naked enum as return value like this:
[OperationContract, ProtoBehavior]
SimpleEnum GetNakedEnum();
(using r622)
Thanks.
Original comment by olischul...@gmail.com
on 1 Feb 2013 at 8:10
Hi again,
I think poster of #4 is correct. There is a missing call to ReadFieldHeaders()
in TagDecorator.Read(). After I added the call it was working in my
environment. Find attached the diff for TagDecorator.cs to r262. I also added
the call to TagDecorator.EmitRead().
Regards,
Oliver.
Original comment by olischul...@gmail.com
on 1 Feb 2013 at 2:16
Attachments:
It would not normally be correct to query the field-header there. I'll take a
look, but that sounds dubious at first glance.
Original comment by marc.gravell
on 1 Feb 2013 at 2:45
We're trying to switch to v2 (r640) and we're having issues as well regarding
(so it seems) returning an enum value from a WCF call.
Any progress on this issue since it does sound similar?
Original comment by T...@aimproductions.be
on 13 Jul 2015 at 10:24
Original issue reported on code.google.com by
dsparkp...@gmail.com
on 31 Jul 2012 at 7:42