我们正在使用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环境下编译了dll(紧凑框架.net 3.5),也许它不适用于monotouch。