Bug 16951 - [PCL] ReadOnlyDictionary is missing from the System.ObjectModel facade
Summary: [PCL] ReadOnlyDictionary is missing from the System.ObjectModel facade
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.0.6.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2013-12-23 21:31 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-11-10 13:16 UTC (History)
4 users (show)

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

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 Brendan Zagaeski (Xamarin Team, assistant) 2013-12-23 21:31:08 UTC
The System.ObjectModel.dll facade assembly for Xamarin.iOS does not export the ReadOnlyDictionary type, so using ReadOnlyDictionary from a PCL does not work. On the other hand, using ReadOnlyDictionary directly in a Xamarin.iOS project _does_ work.

## Steps to reproduce

1. Create a new Xamarin.iOS project, and a new PCL Profile7 (.NET 4.5 + Windows Store) PCL project.

2. Reference the ReadOnlyDictionary type in the PCL project. For example, add a subclass:
> public class MyDictionary<TKey, TValue> : ReadOnlyDictionary<TKey, TValue>
> {
> 	public MyDictionary (IDictionary<TKey, TValue> dictionary) : base (dictionary)
> 	{
> 	}
> }

3. Reference the subclass from the Xamarin.iOS project:
> new MyDictionary<string, string>(new Dictionary<string, string>());

4. Attempt to build the Xamarin.iOS project

## Result

> error CS1684: Reference to type `System.Collections.ObjectModel.ReadOnlyDictionary`2<TKey,TValue>' claims it is defined assembly `System.ObjectModel, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a', but it could not be found

## Additional information

`monodis --exported` confirms that the type is not present in the Xamarin.iOS facade:
> $ monodis --exported /Developer/MonoTouch/usr/lib/mono/2.1/Facades/System.ObjectModel.dll | grep Dictionary

... but is present in the Xamarin.Android facade:
> $ monodis --exported /Library/Frameworks/Xamarin.Android.framework/Versions/4.10.1-68/lib/xbuild-frameworks/MonoAndroid/v1.0/Facades/System.ObjectModel.dll | grep Dictionary
> 1: System.Collections.ObjectModel.ReadOnlyDictionary`2 is in assemblyref 1, index=200077d, flags=0x200000

## Possible workaround

One workaround seems to be to copy the System.ObjectModel.dll facade assembly from Xamarin.Android:
> C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.ObjectModel.dll

... to the Xamarin.iOS folder:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v1.0\Facades\System.ObjectModel.dll

And on the Mac build host, from:
> /Library/Frameworks/Xamarin.Android.framework/Versions/4.10.1-68/lib/xbuild-frameworks/MonoAndroid/v1.0/Facades/System.ObjectModel.dll

... to:
> /Developer/MonoTouch/usr/lib/mono/2.1/Facades/System.ObjectModel.dll

## Version information
Problem and workaround tested on:
- Xamarin.iOS 7.0.4     and Mono 3.2.5
- Xamarin.iOS and Mono 3.2.6
Comment 2 Dave Dunkin 2014-01-06 17:41:28 UTC
Interestingly, the MSDN don't list ReadOnlyDictionary as PCL compatible (http://msdn.microsoft.com/en-us/library/gg712875(v=vs.110).aspx) but it is a part of Microsoft's facades (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile7\System.ObjectModel.dll).
Comment 3 Martin Baulig 2014-01-07 09:22:16 UTC
It is marked as conditional.  The most likely reason for this is that it was not part of XI's API in October.
Comment 4 Martin Baulig 2014-01-07 10:09:13 UTC
I have removed the conditional:

We need to bump XI to this revision.

This was the only difference in this Facade Assembly between XI and XA, so copying the one from XA is a good workaround.
Comment 5 René Ruppert 2014-02-25 04:13:53 UTC
Not fixed in X.iOS 7.0.6

System.TypeLoadException: Could not load type 'System.Collections.ObjectModel.ReadOnlyDictionary`2' from assembly 'System.ObjectModel, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[SDSClient_Core.Services.REMOTE_SERVICE_ERROR_CODES].Start[<UploadFileAsync>d__51] (SDSClient_Core.Services.Implementations.<UploadFileAsync>d__51& stateMachine) [0x0001b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/AsyncTaskMethodBuilder_T.cs:107 
  at SDSClient_Core.Services.Implementations.DefaultRemoteService.UploadFileAsync (Int32 dataRoomId, System.String fileName, System.String comment, System.String[] parentPathParts, DateTime expiration, System.IO.Stream sourceStream, IProgress`1 progress, CancellationToken ct) [0x00000] in <filename unknown>:0 
  at SDSClient_Core.RemoteDataAccess+<>c__DisplayClass76.<UploadFileAsync>b__74 () 

Just hit the same problem here in my project. I don't want to start copying DLLs around. Does that mean the only option for now is to NOT use ReadOnlyDictionary?

Will this issue be addressed/fixed?
Comment 6 Dave Dunkin 2014-03-11 16:41:45 UTC
This is still an issue in
Comment 7 Martin Baulig 2014-03-12 09:55:11 UTC
Can you guys please REOPEN the bug when a fix is not working for you?  My default bug list does not include anything in the RESOLVED FIXED state, so it's easy to miss out that further action is required.  Thanks.
Comment 8 René Ruppert 2014-03-12 12:28:35 UTC
I'd love to do that but I don't have permissions.
Comment 9 Marek Safar 2016-11-10 13:16:56 UTC
Closing as the issue was fixed some time ago