Bug 19719 - Referencing Protobuf-net.dll gives compilation error only for iOS project but not android
Summary: Referencing Protobuf-net.dll gives compilation error only for iOS project but...
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-05-13 07:50 UTC by Mustafa Shaik
Modified: 2014-05-22 06:55 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Sample to test ProtoBuf on iOS & Android (683.54 KB, application/zip)
2014-05-13 07:50 UTC, Mustafa Shaik
XS screenshot (28.47 KB, image/png)
2014-05-13 08:06 UTC, Sebastien Pouliot

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Mustafa Shaik 2014-05-13 07:50:21 UTC
Created attachment 6790 [details]
Sample to test ProtoBuf on iOS & Android

Whenever I include Protobuf-net.dll into my iOS project I am getting some compilation error. 

Error MT2002: Failed to resolve "System.Void System.ComponentModel.ImmutableObjectAttribute::.ctor(System.Boolean)" reference from "System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" (MT2002)

But this works fine with Android and executes well.

I am attaching the code with this ticket. Any help is highly appreciable.

Comment 1 Sebastien Pouliot 2014-05-13 08:04:18 UTC
"System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"

^ this is not the version of System.dll that ships with Xamarin.iOS (XI). That version should be

The reason this won't work is because the linker is run (by default) for device builds. That does not happen (at least for DEBUG) on Android devices. 

In any case such error would affect the AOT compilation later (Android will fail at JIT time, i.e. at runtime, if the code that uses this is executed).

The fix this properly you need to use a ProtoBuf.dll that is compiled with XI version of System.dll _or_ compiled againt a PCL profile that is compatible with XI.
Comment 2 Sebastien Pouliot 2014-05-13 08:06:10 UTC
Created attachment 6791 [details]
XS screenshot

When I try to open your project I can see XS (latest version) complaining that two assemblies are not available for the right (XI) framework.
Comment 3 Sebastien Pouliot 2014-05-13 08:10:27 UTC
I strongly suggest you to use the PCL version (e.g. using NuGet) of Protobuf [1].  You might also need to do the same for Newtonsoft.Json.

[1] http://stackoverflow.com/a/20092118
Comment 4 Mustafa Shaik 2014-05-14 05:06:14 UTC
Please readd them as follows:

Protobuff-net.dll from ../ProtoBufTest/SerializerTestLib/SerializerTestLib/bin/Release/protobuf-net.dll
SerializerTestLib from ../ProtoBufTest/SerializerTestLib/SerializerTestLib/bin/Release/SerializerTestLib.dll

For this please compile the SerializerTestLib first to get these dlls.

Hope this helps.
Comment 5 Sebastien Pouliot 2014-05-14 08:12:26 UTC
@Mustafa yes I know how to "workaround" the XS warnings.

However that warning is there to tell you it won't work. So while you can workaround it (nad it might work on the JIT/simulator) you'll find yourselve in the situation I described (when trying on devices, AOT).

The fix is to use the PCL versions or rebuild your 2nd project based on the BCL shipped with XI.
Comment 6 Mustafa Shaik 2014-05-22 06:55:39 UTC
That works! I used the one from the following link http://code.google.com/p/protobuf-net/downloads/list, "protobuf-net r668/Full/portable/protobuf-net.dll". This works same for iOS & Android.