Skip to content

Source generated resolver requires C# 9 #1925

Description

@AlanLiu90

Bug description

Source generated resolver requires C# 9. .netstandard 2.0 project needs to add <LangVersion>9.0</LangVersion> to avoid compilation error. There are two parts of code causing this issue:

  1. The following code causes "Feature 'target-type object creation' is not available in C# 7.3. Please use language version 9.0 or greater."
private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, int> closedTypeLookup = new(24)
{
    // ...
}
  1. The following code causes "Feature 'recursive patterns' is not available in C# 7.3. Please use language version 8.0 or greater."
return closedKey switch
{
  0 => new MsgPack::Formatters.ListFormatter<int>(),
  // ...
}

Repro steps

Use MessagePack 3.x in a .netstandard 2.0 project

Expected behavior

.netstandard 2.0 doesn't need to change language version.

Actual behavior

.netstandard 2.0 project needs to add <LangVersion>9.0</LangVersion> to avoid compilation error.

  • Version used: 3.0.134-beta
  • Runtime: .NET Core

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions