Referencing certain NuGets in a Wpf project and using STJ source generation the build breaks.
MSBuild version 17.5.0+6f08c67f3 for .NET
Determining projects to restore...
Restored <projdir>\WpfApp1.csproj (in 352 ms).
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(9,6): error CS0579: Duplicate 'global::System.CodeDom.Compiler.GeneratedCodeAttribute' attribute [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\JsonStuff.cs(4,22): error CS8646: 'IJsonTypeInfoResolver.GetTypeInfo(Type, JsonSerializerOptions)' is explicitly implemented more than once. [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.String.g.cs(10,102): error CS0102: The type 'JsonInfo' already contains a definition for '_String' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.String.g.cs(14,100): error CS0102: The type 'JsonInfo' already contains a definition for 'String' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.String.g.cs(19,101): error CS0111: Type 'JsonInfo' already defines a member called 'Create_String' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(10,104): error CS0102: The type 'JsonInfo' already contains a definition for '_StringArray' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(14,102): error CS0102: The type 'JsonInfo' already contains a definition for 'StringArray' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(19,103): error CS0111: Type 'JsonInfo' already defines a member called 'Create_StringArray' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(51,22): error CS0111: Type 'JsonInfo' already defines a member called 'StringArraySerializeHandler' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(13,71): error CS0102: The type 'JsonInfo' already contains a definition for 's_defaultOptions' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(22,42): error CS0102: The type 'JsonInfo' already contains a definition for 's_defaultContext' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(27,40): error CS0102: The type 'JsonInfo' already contains a definition for 'Default' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(32,76): error CS0102: The type 'JsonInfo' already contains a definition for 'GeneratedSerializerOptions' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(35,16): error CS0111: Type 'JsonInfo' already defines a member called 'JsonInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(40,16): error CS0111: Type 'JsonInfo' already defines a member called 'JsonInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(44,78): error CS0111: Type 'JsonInfo' already defines a member called 'GetRuntimeProvidedCustomConverter' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.GetJsonTypeInfo.g.cs(11,86): error CS0111: Type 'JsonInfo' already defines a member called 'GetTypeInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.GetJsonTypeInfo.g.cs(26,141): error CS0111: Type 'JsonInfo' already defines a member called 'global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.GetTypeInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
Build FAILED.
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(9,6): error CS0579: Duplicate 'global::System.CodeDom.Compiler.GeneratedCodeAttribute' attribute [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\JsonStuff.cs(4,22): error CS8646: 'IJsonTypeInfoResolver.GetTypeInfo(Type, JsonSerializerOptions)' is explicitly implemented more than once. [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.String.g.cs(10,102): error CS0102: The type 'JsonInfo' already contains a definition for '_String' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.String.g.cs(14,100): error CS0102: The type 'JsonInfo' already contains a definition for 'String' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.String.g.cs(19,101): error CS0111: Type 'JsonInfo' already defines a member called 'Create_String' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(10,104): error CS0102: The type 'JsonInfo' already contains a definition for '_StringArray' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(14,102): error CS0102: The type 'JsonInfo' already contains a definition for 'StringArray' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(19,103): error CS0111: Type 'JsonInfo' already defines a member called 'Create_StringArray' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.StringArray.g.cs(51,22): error CS0111: Type 'JsonInfo' already defines a member called 'StringArraySerializeHandler' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(13,71): error CS0102: The type 'JsonInfo' already contains a definition for 's_defaultOptions' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(22,42): error CS0102: The type 'JsonInfo' already contains a definition for 's_defaultContext' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(27,40): error CS0102: The type 'JsonInfo' already contains a definition for 'Default' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(32,76): error CS0102: The type 'JsonInfo' already contains a definition for 'GeneratedSerializerOptions' [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(35,16): error CS0111: Type 'JsonInfo' already defines a member called 'JsonInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(40,16): error CS0111: Type 'JsonInfo' already defines a member called 'JsonInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.g.cs(44,78): error CS0111: Type 'JsonInfo' already defines a member called 'GetRuntimeProvidedCustomConverter' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.GetJsonTypeInfo.g.cs(11,86): error CS0111: Type 'JsonInfo' already defines a member called 'GetTypeInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
<projdir>\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\JsonInfo.GetJsonTypeInfo.g.cs(26,141): error CS0111: Type 'JsonInfo' already defines a member called 'global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.GetTypeInfo' with the same parameter types [<projdir>\WpfApp1_oet233uf_wpftmp.csproj]
0 Warning(s)
18 Error(s)
Can't use STJ source generator together with libraries that also depend on STJ. E.g. BackgroundService from Microsoft.Extensions.Hosting or stuff from Microsoft.Extensions.Configuration.Json
Description
Referencing certain NuGets in a Wpf project and using STJ source generation the build breaks.
Reproduction Steps
Microsoft.Extensions.Hostingor anything that indirectly depends onSystem.Text.Jsondotnet build, VS, whateverMinimal repro code: https://gist.github.com/bachratyg/09df487726946b05728d5129044ca574
Expected behavior
Should build just fine
Actual behavior
Output from dotnet build
Regression?
Might be related to #6792 (pull #6793, #6799)
Known Workarounds
None that I found. Tried #6680 (comment) as suggested in #6792, didn't work
Impact
Can't use STJ source generator together with libraries that also depend on STJ. E.g.
BackgroundServicefromMicrosoft.Extensions.Hostingor stuff fromMicrosoft.Extensions.Configuration.JsonConfiguration
Does not seem to be specific to configuration
dotnet --info
Other information
No response