[Breaking change]: Disallow creating a type of array of System.Void #38311
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 9
Work items for the .NET 9 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
Creating System.Type instance for array of System.Void is no longer allowed.
Version
.NET 9 Preview 1
Previous behavior
typeof(void).MakeArrayType()
returned System.Type instance.New behavior
typeof(void).MakeArrayType()
throws an exception.Type of breaking change
Reason for change
Array of System.Void is an invalid type. This type is rejected in number of situations (e.g.
void[]
in C# does not compile) and it is not possible to create arrays of this type..NET runtimes allowed this invalid type to be created in some situations. However, attempts to use this invalid type lead in other .NET runtime APIs often lead to unexpected behaviors. It is better to disallow creating these invalid array types in all situations to make the behavior robust and consistent.
Recommended action
Remove code that tries to create a type for array of System.Void.
Feature area
Core .NET libraries
Affected APIs
System.Type.MakeArrayType
Associated WorkItem - 196554
The text was updated successfully, but these errors were encountered: