thomius
thomius

Reputation: 824

Where is ImmutableArray?

Why does ImmutableArray seem to not be there in Microsoft Immutable Collections NuGet package version 1.0.34?

enter image description here

Upvotes: 7

Views: 2364

Answers (2)

Jean Hominal
Jean Hominal

Reputation: 16796

ImmutableArray is not present in your version of the library.

As you can see in the version history, the release notes for 1.1.20 mention "Re-included ImmutableArray<T>"

You can find the explanation for why ImmutableArray was absent from the 1.0 version on the .NET blog, in this announcement. (In short - the Roslyn team had a noticeable performance hit when they tried to use that type instead of regular arrays, and the team in charge of the library was not sure how to fix that, while keeping a reasonable API.)

You will find newer versions of the library under its new NuGet package, System.Collections.Immutable.

N.B.: According to the source code in the new versions of System.Collections.Immutable, they have apparently decided to take the API hit - that is, some operations on a unitialized ImmutableArray will throw a surprising NullReferenceExceptions. Clearly, ImmutableArray should never be instantiated with new. (ImmutableArray<T>.Empty should be used instead)

Upvotes: 8

Alasjo
Alasjo

Reputation: 1240

From the documentation:

public static class ImmutableArray

The ImmutableArray is static, so you can't instantiate it. Use:

ImmutableArray.Create<T>(); // Creates an empty immutable array

Upvotes: 1

Related Questions