Version Used:
Steps to Reproduce:
- Launch VS under a debugger.
- Set a breakpoint at
|
var errorCode = isInit ? provider.WRN_GeneratorFailedDuringInitialization : provider.WRN_GeneratorFailedDuringGeneration; |
[remaining steps are in the debugee]
- Create a new .NET 6 console app.
- Expand the analyzers node, and observe System.Text.Json.SourceGeneration is not producing any files
- Paste in the following contents:
class Person { }
internal partial class MyJsonContext : JsonSerializerContext
{
}
- Observe still no generated files.
- Add
[JsonSerializable(typeof(Person))] before the MyJsonContext class.
- Observe there are now generated files.
- Delete the attribute
- Observe that exceptions are now being thrown from the generator:
SyntaxTree is not part of the compilation
Parameter name: syntaxTreeat Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility) in F:\Projects\Roslyn\src\Compilers\CSharp\Portable\Compilation\CSharpCompilation.cs:line 2256
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility) in F:\Projects\Roslyn\src\Compilers\CSharp\Portable\Compilation\CSharpCompilation.cs:line 3547
at Microsoft.CodeAnalysis.Compilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility) in F:\Projects\Roslyn\src\Compilers\Core\Portable\Compilation\Compilation.cs:line 211
at System.Text.Json.SourceGeneration.JsonSourceGenerator.Parser.GetGenerationSpec(IEnumerable`1 classDeclarationSyntaxList)
at System.Text.Json.SourceGeneration.JsonSourceGenerator.Execute(Compilation compilation, ImmutableArray`1 contextClasses, SourceProductionContext sourceProductionContext)
at System.Text.Json.SourceGeneration.JsonSourceGenerator.<Initialize>b__4_3(SourceProductionContext spc, ValueTuple`2 source)
at Microsoft.CodeAnalysis.UserFunctionExtensions.<>c__DisplayClass3_0`2.<WrapUserAction>b__0(TInput1 input1, TInput2 input2) in F:\Projects\Roslyn\src\Compilers\Core\Portable\SourceGeneration\UserFunction.cs:line 66
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
My hunch here is when we are removing the attributes, we're still keeping around the old one for later generation passes which is now stale.
Version Used:
Steps to Reproduce:
roslyn/src/Compilers/Core/Portable/SourceGeneration/GeneratorDriver.cs
Line 298 in 0734ecd
[remaining steps are in the debugee]
[JsonSerializable(typeof(Person))]before the MyJsonContext class.My hunch here is when we are removing the attributes, we're still keeping around the old one for later generation passes which is now stale.