Skip to content

[Breaking change]: Disallow creating a type of array of System.Void #38311

Closed

Description

@jkotas

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


Associated WorkItem - 196554

Activity

  1. added
    📌 seQUESTeredIdentifies that an issue has been imported into Quest.
    and removed
    🗺️ reQUESTTriggers an issue to be imported into Quest.
    on Jan 3, 2024
  2. moved this from 🔖 Ready to 👀 In review in dotnet/docs January 2024 sprinton Jan 18, 2024
  3. ghost added
    in-prThis issue will be closed (fixed) by an active pull request.
    on Jan 18, 2024
  4. ghost removed
    in-prThis issue will be closed (fixed) by an active pull request.
    on Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 9Work items for the .NET 9 release📌 seQUESTeredIdentifies that an issue has been imported into Quest.breaking-changeIndicates a .NET Core breaking change

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions