Skip to content

Troubleshooting

This appendix compiles common problems and solutions encountered during source generator development. For detailed information about debugging setup, refer to Part 1-03. Debugging Setup.


SymptomCauseSolution
Generated code is not visiblePrevious results remain in build cacheDelete bin/obj folders and rebuild
Code changes are not reflectedIDE is caching the previous generator DLLFully close Visual Studio → delete bin/obj → restart
Compile error: duplicate type definitionOutputItemType missing from project referenceVerify OutputItemType="Analyzer"
Generator does not runMissing [Generator] attribute or IIncrementalGenerator not implementedVerify [Generator(LanguageNames.CSharp)] on generator class
Terminal window
# Batch delete bin/obj
Get-ChildItem -Recurse -Directory -Include bin,obj | Remove-Item -Recurse -Force

SymptomCauseSolution
Breakpoints not working (hollow circle)Build cache and source mismatchClear cache → dotnet clean → rebuild
Debugger.Launch() popup doesn’t appearRelease build or #if DEBUG condition not metVerify Debug build configuration, check AttachDebugger: true setting
Cannot step into generator from testsTest project has ReferenceOutputAssembly="false"Change to ReferenceOutputAssembly="true"
IDE not selected after Debugger.Launch()Multiple Visual Studio instances runningClose all but one instance

SymptomCauseSolution
Verify snapshot mismatchGenerated code has changed (intentionally or not)Review changes and run Build-VerifyAccept.ps1
Required assembly missing in CSharpCompilationInsufficient reference types in RequiredTypes arrayAdd needed types to SourceGeneratorTestRunner’s RequiredTypes
NullReferenceException in testsGenerator did not produce codeVerify [GenerateObservablePort] and IObservablePort implementation in input source
Diagnostic test failureUsing Generate instead of GenerateWithDiagnosticsUse GenerateWithDiagnostics method for diagnostic verification
Terminal window
# Approve all pending snapshots
./Build-VerifyAccept.ps1

SymptomCauseSolution
Slow buildIncremental caching not workingVerify data model is record struct (value equality required)
IDE unresponsiveDebugger.Launch() left in true stateRestore to AttachDebugger: false
Build delay in large projectsGenerator traversing all Syntax NodesNarrow filtering scope with ForAttributeWithMetadataName

You can directly view generated code in Visual Studio Solution Explorer:

Solution Explorer
→ Dependencies
→ Analyzers
→ Functorium.SourceGenerators
→ Functorium.SourceGenerators.ObservablePortGenerator
→ GenerateObservablePortAttribute.g.cs
→ Repositories.UserRepositoryObservable.g.cs

Expressions useful for understanding source generator internal state during debugging:

// Full class name
classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
// → "global::MyApp.Adapters.UserRepository"
// All interfaces
classSymbol.AllInterfaces.Select(i => i.Name).ToArray()
// → ["IUserRepository", "IObservablePort"]
// Method signature
method.ToDisplayString()
// → "GetUserAsync(int)"
// Return type
method.ReturnType.ToDisplayString()
// → "LanguageExt.FinT<LanguageExt.IO, User>"
Terminal window
# Generate detailed log
dotnet build MyProject.csproj -v:diag > build.log
# Search for source generator related logs
grep -i "sourcegenerator" build.log

Part 1-03. Debugging Setup