Skip to content

Microsoft.XmlSerializer.Generator not working with any .NET Standard 2.0 library #83765

Open

Description

@topsterde

Description

Microsoft.XmlSerializer.Generator does not find the Span<> type when .NET Standard 2.0 is used.

Reproduction Steps

Just compile the attached example:
XmlSerializerAppWithGenerator.zip

Expected behavior

*.XmlSerializer.dll is generated

Actual behavior

CS0234: The type or namespace "Span<>"
warning : SGEN: Failed to generate the serializer for XmlSerializerLibWithGenerator.dll

Regression?

No response

Known Workarounds

Change <TargetFramework>netstandard2.0</TargetFramework> to <TargetFramework>netstandard2.1</TargetFramework>

Configuration

.NET SDK:
Version: 7.0.202
Commit: 6c74320bc3

OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.202\

Host:
Version: 7.0.4
Architecture: x64
Commit: 0a396ac

.NET SDKs installed:
6.0.405 [C:\Program Files\dotnet\sdk]
7.0.202 [C:\Program Files\dotnet\sdk]

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 22, 2023
  2. vcsjones commented on Mar 22, 2023

    @vcsjones
    Member

    If I add a package reference to System.Memory then the problem goes away. The project file looks like:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
      </PropertyGroup>
        <ItemGroup>
            <PackageReference Include="Microsoft.XmlSerializer.Generator" Version="7.0.0" PrivateAssets="All" />
            <PackageReference Include="System.Memory" Version="4.5.5" />
        </ItemGroup>
        <ItemGroup>
            <DotNetCliToolReference Include="Microsoft.XmlSerializer.Generator" Version="7.0.0" />
        </ItemGroup>
    </Project>
  3. added this to the 8.0.0 milestone on Mar 30, 2023
  4. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Mar 30, 2023
  5. topsterde commented on Apr 3, 2023

    @topsterde
    Author

    It also does not work for .NET Framework libraries, that do not reference System.Memory.

  6. modified the milestones: 8.0.0, 9.0.0 on May 23, 2024
  7. modified the milestones: 9.0.0, 10.0.0 on Dec 9, 2024
  8. modified the milestones: 10.0.0, 11.0.0 on Aug 19, 2025
  9. modified the milestones: 11.0.0, 12.0.0 on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions