iPhone 的 Protobuf-net v2 alpha 编译 dll 问题

发布于 2024-10-27 09:06:20 字数 1848 浏览 3 评论 0原文

我们正在使用 unity3d(monotouch) 引擎 (C#) 开发一款跨平台在线游戏,并使用 protobuf-net(感谢 Marc Gravell)作为协议。 众所周知,反射在 iOS 上不起作用。 Apple 不允许动态生成代码。我们查了Marc的博客(http://marcgravell.blogspot.com/),发现早期的protobuf-net v2(虽然还没有完成)可以避免反射问题。

我们做了一些测试并尝试将序列化代码预编译到dll文件中,但是,当我们在ios上运行它时,我们收到以下消息。

>

     System.IO.FileNotFoundException has been thrown
>     “Could not load file or assembly “DataBuilder , Version=0.0.0.0 , 
> Culture = neutrual , PublicKeyToken =
> null ”” or one of its dependencies.”

这是我们的编译dll代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProtoBuf;
using ProtoBuf.Meta;
using Data;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var bb = TypeModel.Create();
            bb.Add(typeof(Customer), true);
            bb.Compile("DataBuilder", "databuilder.dll");
        }
    }
}   

这是我们的测试代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using System.IO;
using ProtoBuf;
using ProtoBuf.Meta;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var creater = new DataBuilder();  // that's it

            var dd = new Data.Customer();
            dd.Name = "Hellow World";
            dd.CustomerId = "1232";
            MemoryStream mm = new MemoryStream();
            creater.Serialize(mm, dd);
            mm.Seek(0, SeekOrigin.Begin);
            Data.Customer c = (Data.Customer)creater.Deserialize(mm, null, typeof(Data.Customer));
            Console.WriteLine(c.Name);
        }
    }
}

我们在Windows环境(compact Framework .net 3.5)下编译了dll,也许它在monotouch上不起作用。

We're developing a cross-platform online game using unity3d(monotouch) engine (C#), and we use protobuf-net (thanks to Marc Gravell) as protocol.
As we know, reflection does not work on iOS. It is not allowed by Apple to have code generated dynamically. We checked Marc's blog (http://marcgravell.blogspot.com/), and found the early protobuf-net v2(though it's not completed yet) may avoid reflection problem.

we made some test and try to pre-compile serialize code into dll file, howerver, when we run it on ios , we got the following message.

>

     System.IO.FileNotFoundException has been thrown
>     “Could not load file or assembly “DataBuilder , Version=0.0.0.0 , 
> Culture = neutrual , PublicKeyToken =
> null ”” or one of its dependencies.”

here is our compile dll code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProtoBuf;
using ProtoBuf.Meta;
using Data;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var bb = TypeModel.Create();
            bb.Add(typeof(Customer), true);
            bb.Compile("DataBuilder", "databuilder.dll");
        }
    }
}   

here is our test code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using System.IO;
using ProtoBuf;
using ProtoBuf.Meta;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var creater = new DataBuilder();  // that's it

            var dd = new Data.Customer();
            dd.Name = "Hellow World";
            dd.CustomerId = "1232";
            MemoryStream mm = new MemoryStream();
            creater.Serialize(mm, dd);
            mm.Seek(0, SeekOrigin.Begin);
            Data.Customer c = (Data.Customer)creater.Deserialize(mm, null, typeof(Data.Customer));
            Console.WriteLine(c.Name);
        }
    }
}

We compiled dll under Windows enviornment(compact framework .net 3.5), maybe it didn't work on monotouch.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文