Description
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
- Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
- Behavioral change: Existing binaries may behave differently at run time.
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