Skip to content

Nullability removed when creating anonymous type #83114

@rolfbjarne

Description

@rolfbjarne

Version Used:

$ dotnet --version
10.0.201

Steps to Reproduce:

Repro: https://lab.razor.fyi/#fY9BSwMxEIXp3jI3exLxMOSk0IZkoQVZREQvCop4FcEY0yWyJiXJbpUlf8R_4L-UDdUtHrwMj_e9x8zAVwFw513t5RtTYfpZgGpkCLj1oAdExBBlNAo7Z17wRhp7dJztHggJ0Rtb48PjGdq2ac69lx94mnX1B7vb3YDe4C_EHumlfm5rOkN6rxstg6aYKgBCOulx7d2rVvHKrlzYdocSEEIGnQW5cHZl6tbLaJzNsZ91s4GnPP-Lj_eNhVTlTxMkmO4t2JLxecnKpVicMCHKg33BGWd8vva6M3ozEnooBONM8B020utChafJ--Qb

Sample code:

string []? nullArray = null;
string []? noNullArray = new string [] { "Debug", "Release" };

var projectInfos = new [] {
	new {
		Configurations = nullArray,
	},
	new {
		Configurations = noNullArray,
	},
};

Expected Behavior:

No warning

Actual Behavior:

warning CS8619: Nullability of reference types in value of type '<anonymous type: string[] Configurations>' doesn't match target type '<anonymous type: string[]? Configurations>'.

It seems the nullable noNullArray ends up being a non-nullable type at some point, causing a type mismatch in the anonymous type.

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions