1

I am playing with the beta of Protobuf-net v2 (r363 from the SVN). I built it using Visual Studio 2010, the project Proto 2010.sln, and from there protobuf-net_Phone7 using the Silverlight 2 configuration. I can reference the resulting dll from Windows Phone 7 projects. I am mentioning all this because I am not 100% sure that this is the right way to build it.

Assuming it is the right one, I tried to build a very simple project but it fails. I get a MissingMethodException at ProtoBuf.Serializers.TypeSerializer.CreateInstance(ProtoReader source) when attempting to Deserialize. This same code (but in a Form instead of a Page) works fine on the same version of protobuf-net v2 that I built for Windows Mobile 6.5, so I wonder if I either built it incorrectly or there is a different way to use it in WP7.


    [ProtoContract]
    public class Person
    {
        [ProtoMember(1)]
        public int Id { get; set; }
        [ProtoMember(2)]
        public string Name { get; set; }
        [ProtoMember(3)]
        public Address Address { get; set; }
    }
    [ProtoContract]
    public class Address
    {
        [ProtoMember(1)]
        public string Line1 { get; set; }
        [ProtoMember(2)]
        public string Line2 { get; set; }
    }

    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Person person = new Person();
            person.Address = new Address();
            person.Address.Line1 = "First Line";
            person.Address.Line2 = "Second Line";
            person.Id = 1;
            person.Name = "Name";
            MemoryStream ms = new MemoryStream();

            Serializer.Serialize(ms, person);
            ms.Position = 0;
            Person person2 = Serializer.Deserialize(ms);
            ms.Position = 0;

        }

    }
cloudraven
  • 2,484
  • 1
  • 24
  • 49
  • 1
    Have you looked through this? http://marcgravell.blogspot.com/2010/04/walkthrough-protobuf-net-on-phone-7.html – Marc Gravell Mar 28 '11 at 19:17
  • I can't get that to work either. I cannot make a reference to MySerializer.dll from the WP7 app because "it was not built using the Windows Phone runtime". I created using the regular (and I assume that is the full framework version) on a regular console (windows console application). Anyway... will that be the only way to use protobuf-net in wp7? I am actually trying to use some code I have for v1 in wm6.5 and wp7 and also deal with this issue http://stackoverflow.com/questions/2706177/protocol-buffer-deserialization-and-a-dynamically-loaded-dll-in-compact-framework – cloudraven Mar 28 '11 at 22:00
  • I will need to update and re-check... – Marc Gravell Mar 28 '11 at 22:07

1 Answers1

1

This blog post deals with some options - http://blog.chrishayuk.com/2010/12/protocol-buffers-generator.html - and says its built for WP7

Stuart
  • 66,722
  • 7
  • 114
  • 165
  • Thanks, but that is for the other implementation of protocol buffers for c#. However I didn't know that they supported Compact Framework 3.5 and Windows Phone 7. It's nice to know. – cloudraven Mar 29 '11 at 20:14