Using ConcurrentDictionary in PCL from a UWP Application

I recently had a problem and would like to explain why:

In a portable class library (PCL) using Profile5 (.Net 4, Windows 8) I have this code:

using System.Collections.Concurrent;

public class Foo
{
    public static void Bar(ConcurrentDictionary<string, bool> dict)
    {
        dict.AddOrUpdate("true", true, (k, v) => true);
    }

    public static void Baz()
    {
        new ConcurrentDictionary<string, bool>();
    }
}

Using Bara Windows 10 UWP application, follow these steps:

var dict = new ConcurrentDictionary<string, bool>();
Foo.Bar(dict);

Compiles but crashes:

Method not found: 'Void Foo.Bar (System.Collections.Concurrent.ConcurrentDictionary`2)'.

Baz is accessed differently:

An attempt to 'Foo.Baz ()' to access the 'System.Collections.Concurrent.ConcurrentDictionary`2..ctor ()' method failed.

, , TypeForwardedTo . , ( ), .

, 2 ConcurrentDictionary :

  • System.Collections.Concurrent.ConcurrentDictionary'2[[TKey, TValue]], System.Collections.Concurrent, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, typeof(ConcurrentDictionary<,>)
  • System.Collections.Concurrent.ConcurrentDictionary'2[[TKey, TValue]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Bar.

PCL , 4.5 4.0 ( System.*), .

, , - - , ? - Microsoft ?

( , "" . , , - )

. , ConcurrentDictionary ( UWP) , , UWP PCL.

+4

Source: https://habr.com/ru/post/1613054/


All Articles