如何在 Windows Phone 7 上使用 protobuf-net v2?

发布于 2024-10-27 08:07:57 字数 1655 浏览 4 评论 0原文

我正在使用 Protobuf-net v2(来自 SVN 的 r363)的测试版。 我使用 Visual Studio 2010、项目 Proto 2010.sln 构建了它,并使用 Silverlight 2 配置从 protobuf-net_Phone7 构建了它。我可以引用 Windows Phone 7 项目生成的 dll。我提到这一切是因为我不能 100% 确定这是构建它的正确方法。

假设它是正确的,我尝试构建一个非常简单的项目,但失败了。尝试反序列化时,我在 ProtoBuf.Serializers.TypeSerializer.CreateInstance(ProtoReader source) 处收到 MissingMethodException。这段相同的代码(但在表单中而不是页面中)在我为 Windows Mobile 6.5 构建的同一版本的 protobuf-net v2 上运行良好,所以我想知道是否我错误地构建了它,或者有不同的使用方式在 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;

        }

    }

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;

        }

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

庆幸我还是我 2024-11-03 08:07:57

这篇博文涉及一些选项 - http://blog.chrishayuk.com /2010/12/protocol-buffers-generator.html - 并表示它是为 WP7 构建的

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文