DerrickBrayanClayton / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

{"The enum System.Net.HttpStatusCode has conflicting values Ambiguous and MultipleChoices"} #88

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. I have a response object that contains "System.Net.HttpStatusCode" 
property
2. The Serializer.NonGeneric.Serialize method constantly throws exception 
on serializing this property at "PropertyUtil.cs" file Line 83.
3. The exception is {"The enum System.Net.HttpStatusCode has conflicting 
values Ambiguous and MultipleChoices"}, even though the Http status code is 
"OK"

What is the expected output? What do you see instead?
I expect HtppStatusCode field to be serialized correctly

What version of the product are you using? On what operating system?
i am using "protobuf-net r278.zip" and "NET30" zip on Windows 7 with VS 
2008

Please provide any additional information below.

Original issue reported on code.google.com by sangeeta...@gmail.com on 22 Jan 2010 at 8:49

GoogleCodeExporter commented 8 years ago
Well, it is correct to an extent, but equally since the wire-value and 
enum-value are 
identical in this case, yes it would be reasonable to accept *either* 300 and 
set the 
value to (essentially) 300. I'll see what I can do,

Original comment by marc.gravell on 24 Jan 2010 at 10:18

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 28 Jan 2010 at 7:25

GoogleCodeExporter commented 8 years ago
r282

Original comment by marc.gravell on 28 Jan 2010 at 7:57

GoogleCodeExporter commented 8 years ago
now i get the following exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the 
target 
of an invocation. ---> ProtoBuf.ProtoException: The default enum value 
(HttpStatusCode.0) is not defined for the optional property StatusCode
   at ProtoBuf.Property.PropertyEnum`2.OnAfterInit()
   at ProtoBuf.Property.Property`1.InitPrivate(Int32 tag, DataFormat dataFormat, 
Boolean isOptional, MemberInfo member, Delegate getValue, Delegate setValue, 
Object 
defaultValue)
   at ProtoBuf.Property.Property`1.Init(MemberInfo member)
   at ProtoBuf.Property.PropertyFactory.Create[T](MemberInfo member)
   at ProtoBuf.Serializer`1.Build()
   at ProtoBuf.Serializer`1.SerializeChecked(T instance, SerializationContext 
destination)
   at ProtoBuf.SerializerItemProxy`2.Serialize(TActualClass instance, 
SerializationContext destination)
   at ProtoBuf.SerializerProxy`1.Serialize(T instance, Stream destination)
   at ProtoBuf.Serializer.Serialize[T](Stream destination, T instance)
   --- End of inner exception stack trace ---

for my use case, i don't need to parse all possible values of an enum. I can 
just 
cast it to the underlying type and be done with it. Can I modify the 
protobuf-net dll 
to do so? or is it under some license?

Original comment by sangeeta...@gmail.com on 29 Jan 2010 at 2:26

GoogleCodeExporter commented 8 years ago
Sorry, I tested with an enum with duplicated values, not specifically 
HttpStatusCode; 
you could always specify a default value ([DefaultValue(...)] or make it 
non-optional 
([ProtoMember(..., IsRequired=true)]).

Another cheeky trick is to serialize the integer value directly:

    [ProtoMember(24)]
    private int StatusSerialized {
        get {return (int)Status;}
        set {Status = (HttpStatusCode)value;}
    }

The source is freely available - you're welcome to modify a local copy.

Original comment by marc.gravell on 29 Jan 2010 at 7:42