leejw51 / protobuf-net

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

Unclear error message when serializing list of class with enum field that does not have default value #119

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When trying to serialize or deserialize class that has a field of Enum type and 
that Enum does not have a default value an exception is thrown with this 
message:
Only data-contract classes (and lists/arrays of such) can be processed (error 
processing List`1)

This does not indicate about the real problem which is shown when trying to 
serialize/deserialize a single instance of the items in the list:
The default enum value (<EnumName>.0) is not defined for the optional property 
<EnumName> 

What steps will reproduce the problem?
1. Add this class
  [ProtoContract]
  public class ClassWithEnum {

    [ProtoMember(1)]
    public string str;

    [ProtoMember(2)]
    public DateTime mydate;

    [ProtoMember(3)]
    public EnumOfMy myEnum;
  }

  public enum EnumOfMy {
    Me = 1
  }
2. Add this to static void main:
      using (MemoryStream ms = new MemoryStream()) {
        ClassWithEnum a = new ClassWithEnum();
        a.str = "hello";
        a.mydate = DateTime.Now;
        a.myEnum = EnumOfMy.Me;
        List<ClassWithEnum> l = new List<ClassWithEnum>();
        l.Add(a);
        Serializer.Serialize(ms, l);
    }

What is the expected output? What do you see instead?
I am expecting to see the real problem, at least as an inner exception.

What version of the product are you using? On what operating system?
Protobuf-net version 1.0.0.280
Windows XP Pro
Visual Studio 2008
.NET Runtime version v2.0.50727

My name is Ido Ran
email: ido.ran@gmail.com

Thank you.

Original issue reported on code.google.com by ido....@gmail.com on 6 Jul 2010 at 4:22

GoogleCodeExporter commented 9 years ago
Thanks - I'll investigate.

Original comment by marc.gravell on 6 Jul 2010 at 6:31