I have one internal static class MyLists with a static member:
internal static ImmutableArray<string> MyList =
new ImmutableArray<string> { "asd", "qwe" };
In another public test class Tests I have a MyTest function which selects and compares the list.
[TestClass]
public class MyTests {
[TestMethod]
public void TestMyLists() {
var list = MyLists.MyList.Select(s => s + ".foo");
}
}
But, I get the following error:
Additional information: The type initializer for 'TestMyLists' threw an exception.
Object reference not set to an instance of an object.
When I debug I see the static ImmutableArray as value = Uninitialized. Why?
According to the docs on ImmutableArray, you should use the
Create()
method instead of using constructor for this type of array, like this:About the reason why, I will point you to the article Please welcome ImmutableArray by Immo Landwerth, where he describes: