Closed canton7 closed 2 years ago
Tagging subscribers to this area: @dotnet/area-system-text-json See info in area-owners.md if you want to be subscribed.
Author: | canton7 |
---|---|
Assignees: | - |
Labels: | `area-System.Text.Json` |
Milestone: | - |
Thanks @canton7 . Are you interested in offering a PR?
Potentially. I had the same issue reported in one of my source generators, and wondered how Microsoft were handling it. Turns out, you don't, hence this issue.
I've started a conversation around changing the behaviour of Roslyn here, as almost every SG will run into this problem. It's not too bad to fix in non-incremental SGs, but the only way I can come up with of fixing it for incremental SGs is just ugly.
Duplicate of #58198.
Description
System.Text.Json.SourceGeneration.JsonSourceGenerator does not make sure that the hintNames it uses are unique. If you pass it two different
JsonSerializerContext
subclasses with the same name in different namespaces (or within different parent classes) it will crash, and will not generate any sources. E.g.:Reproduction Steps
Create a new project targetting .NET 6. Add the following code:
Or:
Observe that JsonSourceGenerator crashes, and does not generate source.
Expected behavior
JsonSourceGenerator copes with two contexts which have the same name but are in different namespaces (or are inner types of different parent types).
Actual behavior
JsonSourceGenerator crashes with the following message, and does not generate source
Regression?
No response
Known Workarounds
No response
Configuration
.NET 6, Visual Studio 17.2.0 Preview 1.0.
Other information
No response