Skip to content

System.Text.Json SG is run twice in WPF projects #10175

Open

Description

@ZzZombo

Description

Similar to dotnet/extensions#4969, the SG is included twice in a compilation, resulting in duplicate definition errors and build failure due to the way WPF is built, involving a temporary project.

Reproduction Steps

  • Start a new WPF project.
  • Create a SG-enabled JSON serialization context, the target type and options do not matter, it should just be minimally functional.
  • Try to build. The Output pane lists the errors twice, once for the temporary project and once, verbatim, for the actual one.

Expected behavior

SG is included only once.

Actual behavior

SG is included twice and prevents the build from finishing successfully.

Regression?

I can't say, sorry. There was one other issue previously but because of two SGs being active at once.

Known Workarounds

I can't say, unless switching back to reflection is considered one.

Configuration

I target net9-windows on Windows 10 x64. It shouldn't be specific to that configuration but I don't know for sure.

Other information

AS I said already, it shows up twice in output, once per each project in the compilation, even though IMO the temp. WPF project shouldn't run the JSON SG at all, so preventing it from running in either when building a WPF application should fix the issue.

Activity

  1. transferred this issue fromdotnet/runtimeon Dec 13, 2024
  2. added
    Investigate
    and removed on Dec 16, 2024
  3. Kuldeep-MS commented on Apr 1, 2025

    @Kuldeep-MS
    Contributor

    @ZzZombo - I attempted to replicate the issue on my end, but it seems I might be missing some setup details. Could you please provide a minimal sample repro application?

  4. ZzZombo commented on Apr 1, 2025

    @ZzZombo
    Author

    @ZzZombo - I attempted to replicate the issue on my end, but it seems I might be missing some setup details. Could you please provide a minimal sample repro application?

    Sure, but fair warning, I'm currently on sick leave and unlikely to get access to the project for a week.

  5. franchyd commented on Apr 1, 2025

    @franchyd

    @ZzZombo - I attempted to replicate the issue on my end, but it seems I might be missing some setup details. Could you please provide a minimal sample repro application?

    I setup a minimal repro here:
    https://gist.github.com/franchyd/5778573e8dfe214336ddd8d08639cb49

    This is a freshly generated project from the WPF template with only the addition of a PackageReference to the csproj and an arbitrary class to trigger the System.Text.Json source generator. I chose to add that class to MainWindow.xaml.cs but it could go anywhere.

    You may note that you can "fix" the issue for this project by removing the PackageReference. In this contrived min-reproduction case this may be an option but in real projects the System.Text.Json could be transitive or the specific version necessary.

  6. franchyd commented on Apr 4, 2025

    @franchyd

    @Kuldeep-MS were you able to reproduce with the sample project?

  7. franchyd commented on May 13, 2025

    @franchyd

    any movement on this?

  8. ericstj commented on Sep 5, 2025

    @ericstj
    Member

    Looks like the same as #9589 (comment) - I added a workaround and reccomended fix there.

  9. added
    regression
    on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Investigateregression

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions