1

Why can't ProtoContract be applied to a custom structure? According to this question and the associate answer and code, structures can obviously be serialized by protobuf-net by using DataContract instead. Are there any disadvantages to using this workaround? ProtoContract says it can only be applied to classes and enums; is this an outdated restriction from v1? I'm using the most recent release (r470).

Community
  • 1
  • 1
dlras2
  • 8,416
  • 7
  • 51
  • 90

1 Answers1

1

In v1 it is not available on struct, which isn't unreasonable since v1 did not support structs. It should work in r470 though; if it isn't working, you probably aren't actually using r470! Here's the code:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
    AttributeTargets.Enum | AttributeTargets.Interface,
    AllowMultiple = false, Inherited = true)]
public sealed class ProtoContractAttribute : Attribute
{ ... }

I'm pretty sure there are tests that use this, and I know for a fact that I did plenty of "day job" work this week serializing structs in this way with v2.

Please check you are using the right dll.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I started off using v1, but uninstalled it and switched to r470. Every reference I have to protobuf-net.dll is version 2.0.0.470. I guess I'll have to figure that part out myself. As always, thanks for your quick help. – dlras2 Nov 06 '11 at 17:10
  • Apparently my problem was with Visual Studio - every reference claimed to be r470, but I was stuck on v1. I unloaded and reloaded everything and it fixed it. – dlras2 Nov 06 '11 at 17:28