Version Used: dotnet sdk 5.0.100-preview.6.20318.15
Steps to Reproduce:
I'm running a project referencing a source generator on the command line via dotnet build.
It displays the warning:
CSC : warning CS8785: Generator 'ContainerSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result.
But does not explain why it failed to generate source.
It appears like there is a catch all in GeneratorDriver which produces this diagnostic:
This should probably log the exception that was thrown @chsienki?
Yeah, its on the board to fix :) https://github.com/dotnet/roslyn/projects/54#card-41652943
Great!
Can I just suggest that this should be really high priority? It's really hard to develop a source generator when you cant even tell what went wrong :-)
For now I'm doing the following as a workaround:
public void Execute(SourceGeneratorContext context)
{
try
{
ExecuteInternal(context);
}
catch (Exception e)
{
//This is temporary till https://github.com/dotnet/roslyn/issues/46084 is fixed
context.ReportDiagnostic(Diagnostic.Create(
new DiagnosticDescriptor(
"SI0000",
"An exception was thrown by the StrongInject generator",
"An exception was thrown by the StrongInject generator: '{0}'",
"StrongInject",
DiagnosticSeverity.Error,
isEnabledByDefault: true),
Location.None,
e.ToString()));
}
}
//By not inlining we make sure we can catch assembly loading errors when jitting this method
[MethodImpl(MethodImplOptions.NoInlining)]
private void ExecuteInternal(SourceGeneratorContext context)
{
...
}
This was implemented as part of https://github.com/dotnet/roslyn/pull/46804
Most helpful comment
This was implemented as part of https://github.com/dotnet/roslyn/pull/46804