Closed
Description
Description
The ImmutableArray.ToBuilder will throw System.NullReferenceException:“Object reference not set to an instance of an object.” with the stacktrace as
System.Collections.Immutable.dll!System.Collections.Immutable.ImmutableArray<int>.Length.get()
System.Collections.Immutable.dll!System.Collections.Immutable.ImmutableArray<int>.ToBuilder()
> GijachekecuYichearcalallnair.dll!Program.<Main>$(string[] args = {string[0]})
Reproduction Steps
Mini repro code:
using System.Collections.Immutable;
var immutableArray = new ImmutableArray<int>();
var builder = immutableArray.ToBuilder();
You can find all my code in https://github.com/lindexi/lindexi_gd/tree/61fa97cc6b5ea61c280364848829beef9f768bdf/Workbench/GijachekecuYichearcalallnair
Expected behavior
It can return the ImmutableArray<T>.Builder
object.
Actual behavior
Throw the NullReferenceException.
Regression?
No response
Known Workarounds
No response
Configuration
dotnet --info
.NET SDK:
Version: 9.0.203
Commit: dc7acfa194
Workload version: 9.0.200-manifests.47fce8c7
MSBuild version: 17.13.20+a4ef1e90f
Other information
Reference:
- ImmutableArray list initialiser throws NullReferenceException #26880
- Getting rid of ImmutableArray<T>.IsDefault ? #26829
The correct way of using it should be:
var builder = ImmutableArray.CreateBuilder<int>();