3
votes

I am using protobuf-net v2 beta r450 (binary distribution) and building a serialization assembly ahead of time using the technique described here:

http://www.frictionpointstudios.com/blog/2011/3/31/using-protobuf-net-serialization-in-unity-iphone.html

I create my serialization assembly on Windows and use it in my MonoTouch project. It works under the simulator. But when run on the device, where AOT compilation only is enforced, I get this error:

attempting to JIT compile method 'ProtoBuf.BufferPool.GetBuffer()' 
while running with --aot-only 

The exception occurs when Serialize() is called:

using (var stream = File.Create(out_file))
{
    serializer.Serialize(stream, settings);
}

Thanks for any help.

2
Hmmm... Very odd! I haven't seen that - it looks like AOT didnt spot the method is needed. I will have to investigate ways of making AOT believe that this is used. - Marc Gravell
Thanks Marc. I can create a ticket with Xamarin if nothing pops out at you. - t9mike
It is at times like these I wish I still had convenient mac access - Marc Gravell
@t9mike please do open a bug report and include a small, self-contained test case so we can duplicate the issue. Some times we can avoid this exception (by reworking the class library) without having to change the user code. Thanks! - poupou
@poupou I submitted bug, bugzilla.xamarin.com/show_bug.cgi?id=1788. The sample is referenced in the ticket, but for others the direct link is github.com/t9mike/ProtoBuf1. - t9mike

2 Answers

2
votes

I grabbed the protobuf-net sources (v2 r470). Use of [ImmutableObject] was indeed one of the issues. I submitted a few minor patches to @MarcGravell via the protobuf-net issue list. I have updated my example at http://github.com/t9mike/ProtoBuf1 with this new assembly. Thanks everyone for the responses.

0
votes

I had an almost similar problem when working with unity (with protobuf-net and iOS), this helped me:

Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");

Credit: https://github.com/antonholmquist/easy-serializer-unity