.NET 6 Preview 7 Blazor WebAssembly won't build if you are using a JsonSerializerContext implementation
See original GitHub issueIn 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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:18 (16 by maintainers)
Top GitHub Comments
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