Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable class library and .NET ConcurrentDictionary

Looking at http://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx, it seems that ConcurrentDictionary and all of its friends in the System.Collections.Concurrent namespace are available for use in a Portable Class Library.

However, when I create either an F# or C# Portable Class Library, even if I explicitly add a reference to mscorlib.dll, the compilation fails when using ConcurrentDictionary.

Why?

like image 288
Okay Avatar asked Aug 30 '12 17:08

Okay


People also ask

What is the difference between .NET Standard and PCL portable class libraries?

NET Standard is platform-agnostic, it can run anywhere, on Windows, Mac, Linux and so on. PCLs can also run cross-platform, but they have a more limited reach. PCLs can only target a limited set of platforms.

What is a portable class library?

The Portable Class Library project enables you to write and build managed assemblies that work on more than one . NET Framework platform. You can create classes that contain code you wish to share across many projects, such as shared business logic, and then reference those classes from different types of projects.

What is ConcurrentDictionary?

ConcurrentDictionary<TKey,TValue> is designed for multithreaded scenarios. You do not have to use locks in your code to add or remove items from the collection. However, it is always possible for one thread to retrieve a value, and another thread to immediately update the collection by giving the same key a new value.

What is .NET class library?

Class libraries are the shared library concept for . NET. They enable you to componentize useful functionality into modules that can be used by multiple applications. They can also be used as a means of loading functionality that is not needed or not known at application startup.


1 Answers

The term "Portable" should be loosely applied right now. When you create the class library project, you get prompted for the targets you want to support. You'll only get ConcurrentDictionary when you select ".NET Framework" and ".NET for Windows Store apps".

Pick any other and the entire namespace disappears.

This will get better over time, I'd assume, but Windows Phone 7, XBox and Silverlight are lagging behind right now.

like image 147
Hans Passant Avatar answered Nov 15 '22 23:11

Hans Passant