Skip to content

NullReferenceException in ImmutableArray.ToBuilder #115104

Closed
@lindexi

Description

@lindexi

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:

The correct way of using it should be:

var builder = ImmutableArray.CreateBuilder<int>();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions