sdk: .NET 6 Preview 7 Blazor WebAssembly won't build if you are using a JsonSerializerContext implementation
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.
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 18 (16 by maintainers)
Commits related to this issue
- Regression test for #19834 — committed to rainersigwald/sdk by rainersigwald 3 years ago
A better workaround for this bug is the following as it addresses all cases:
Here’s a repro - I don’t know what “grab a binlog” means, sorry.
https://github.com/SQL-MisterMagoo/Issue57249
I actually noticed this and mentioned it in our internal Teams channel. I’d keep it separate but I can put up a fix.
Here’s a binlog: msbuild.zip