Reputation: 166
I am a very happy protobuf-net camper. So far I have been using regular protobuf-net with [ProtoMember], [ProtoInclude] and friends markup with great success.
However now I realise I need to move to protobuf-net core, pre-generating serialization classes, specifically to be able to execute in the AOT environment of Unity on iOS.
That is all groovy and I found some good pointers from speficically this blog post and got started migrating my protobuf-net integration, however information on the subject is not exactly littering the interwebs - at least not to an extend covered by my google-fu.
As I run into one obstacle after the other, digging through source to try and figure out what is going on, I grow a bit frustrated. I could really use a sort of overview / intentions / guideline of protobuf-net core vs. the regular brand.
My latest encounter is the "Non-public type cannot be used with full dll compilation" limitation which seems at the moment somewhat arbitrary, but definitely quite annoying given the implications it has on my existing design (the very reason why I was glad to rid myself of the regular .net binary serializer in favour of protobuf-net).
Any experience sharing / postmortem or similar helpful resource would be greatly appreciated.
Edit: Just for completion, here's my serializer generator tool so far: https://gist.github.com/AngryAnt/a19d8c67155163936aae
Upvotes: 2
Views: 960
Reputation: 1063338
The first thing to note is that the article you link to is out of date: there is tooling in protobuf-net itself to help handle this scenario - the precompile tool. Please see http://marcgravell.blogspot.co.uk/2012/07/introducing-protobuf-net-precompiler.html
As for the restriction on non-public types: this limitation is not arbitrary: it is a part of assembly validation by the core .net runtime. A formal assembly cannot reference things that it is not allowed to. If it tried, it wouldn't pass validation. You can get away with some smoke and mirrors when running in-memory, but not as a dll.
However! There is still potentially an option here - in particular [InternalsVisibleTo]
. I've already done some work to make the precompiler do things with this attribute. I suspect that if you are happy to nominate the serialization dll as "allowed", then either it will already work, or it could be tweaked to work. I genuinely cannot remember (without checking) whether this scenario was on of those included - but I suspect it was.
This is probably more of a discussion thing for protobuf-net itself, rather than a stackoverflow question. It might be worth us taking it there instead.
Upvotes: 1