سؤال

I am trying to make use of the ImmutableDictionary in F# using Mono. I'm using the Xamarin IDE.

I have set my target framework to Mono/.Net4.5 and imported the System.Collections.Immutable using the built in Nuget package manager.

The following line

open System.Collections.Immutable

is generating the following two errors

'/Users/UserName/Projects/Xamarin/OrderInfer/OrderInference/MyTest.fs(34,34): Error FS1109: A reference to the type 'System.Collections.Generic.IEnumerable'1' in assembly 'System.Runtime' was found, but the type could not be found in that assembly (FS1109) (MyTest)'

/Users/UserName/Projects/Xamarin/OrderInfer/OrderInference: Error FS1108: The type 'Lazy'2' is required here and is unavailable. You must add a reference to assembly 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. (FS1108) (OrderInference)

The 2nd error suggests I need to reference System.ComponentModel.Composition. Am I able to use it in Mono? If so, is there another assembly I need to reference?

EDIT: Solution removed and reposted below as an answer

هل كانت مفيدة؟

المحلول 2

ImmutableDictionary is abstract so new won't work. It does however provide a number of create methods.

ImmutableDictionary.Create<string, string>()

نصائح أخرى

This problem can be solved by adding a reference to: 'System.ComponentModel.Composition'. In Xamarin's IDE, this is done by using the Edit References Dialog which can be found by right-clicking on the reference in your project. Go to the All tab and search for System.ComponentModel and just add the System.ComponentModel.Composition assembly.

I now have the following two assemblies installed:

System.Collections.Immutable.dll
System.ComponentModel.Composition.dll

My code now reads:

open System
open System.ComponentModel.Composition
open System.Collections.Immutable

type wordPairs = { pairs:ImmutableDictionary<string, string>; count:int} 
let myPairs = {pairs = ImmutableDictionary.Create<string, string>(); count = 0}

Note: As gradbot pointed out (and Immo Landwerth later nitpicked about ;>> ), ImmutableDictionary is a abstract sealed class. And as such, it has no public constructors. So you need to use the .Create method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top