question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET 6 Preview 7 Blazor WebAssembly won't build if you are using a JsonSerializerContext implementation

See original GitHub issue

In preview 6, you introduced the Json source generator, and I created a “MyJsonContext” to enable the source generator.

    [JsonSerializable(typeof(JsonData))]
    internal partial class MyJsonContext : JsonSerializerContext
    {
    }

Now, in preview 7 the System.Text.Json.SourceGeneration assembly gets added to references twice.

image

This leads to build failure as they both generate the same code!

You can see the duplicate reference by simply creating a new BlazorWebAssembly project, but you need to implement a JsonSerializerContext to see the errors.

Configuration

.NET version 6.0.100-preview.7.21379.14 Windows 11 22000.120 Architecture x64 Browser not relevant as the project won’t build.

Regression?

Worked in .NET 6 Preview 6

Other information

Errors from build:

1>Build FAILED. 1> 1>C:\Users\aaaaa\source\repos\JsonPerfTest\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\MyJsonContext.g.cs(6,6,6,60): error CS0579: Duplicate ‘global::System.CodeDom.Compiler.GeneratedCodeAttribute’ attribute 1>C:\Users\aaaaa\source\repos\JsonPerfTest\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\MyJsonContext.String.g.cs(7,101,7,108): error CS0102: The type ‘MyJsonContext’ already contains a definition for ‘_String’ 1>C:\Users\aaaaa\source\repos\JsonPerfTest\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\MyJsonContext.String.g.cs(8,100,8,106): error CS0102: The type ‘MyJsonContext’ already contains a definition for ‘String’ …68 of these errors in total

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
ericstjcommented, Aug 18, 2021

A better workaround for this bug is the following as it addresses all cases:

  <Target Name="FixPackageConflictOverrides" AfterTargets="ResolveTargetingPackAssets">
    <PropertyGroup>
      <PackageConflictPreferredPackages>$([MSBuild]::Unescape($(PackageConflictPreferredPackages)))</PackageConflictPreferredPackages>
    </PropertyGroup>
  </Target>
2reactions
SQL-MisterMagoocommented, Aug 18, 2021

Here’s a repro - I don’t know what “grab a binlog” means, sorry.

https://github.com/SQL-MisterMagoo/Issue57249

Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing .NET 6 Preview 7
We are delighted to release .NET 6 Preview 7. It is the last preview before we enter the (two) Release Candidate (RC) period....
Read more >
What's New for ASP.NET Core & Blazor in .NET 7
NET 7 introduces a new low-level mechanism for using .NET in JavaScript-based apps," Microsoft explained in a September preview. "With this new ...
Read more >
Blazor WebAssembly & Web API on .NET 6 – Full Course (C#)
Learn Blazor WebAssembly and Web API on . NET 6 by building a shopping cart application using C#. This course also provides a...
Read more >
What's Coming for Blazor in .NET 7?
NET Web Assembly Without Blazor UI. If you want to build a web application with a UI that runs on WebAssembly, then Blazor...
Read more >
Tavenem.Wiki.Blazor.Client 0.5.5-preview
This is an implementation of Tavenem.Wiki for Blazor. It is comprised of a pair of Razor class libraries: a Client library which can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found