-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom analyzer silently fails builds, only "csc.exe exited with code 1" is printed #42616
Comments
Unfortunately, to investigate this compiler misbehavior, we need a repro that we can step through. Could you share steps to repro this issue? I can share my direct microsoft email address if this involves sensitive details. If you can repro from the command-line, that is even better. Then you could try adding the |
Tagging @mavasani, in case he recognizes this as a typical failure mode with analyzers that do certain bad things (in which case I'd recommend debugging your custom analyzer) |
Agreed, we need a repro here to investigate and root cause this. |
@EikeStein I see the following in the log. Seems to point to the root of the problem. Is this the problem?
|
Ah is this the issue where analyzer is reporting a multi-line message? I think I filed a compiler bug on it not handling this scenario gracefully and crashing, but I cannot find that bug anymore. |
@jcouv This is the error message that is generated by the analyzer, but it doesn't show up when building with verbosity set to default. So the error message being multiline is whats causing the problem? If thats the case, that should definitaly be documented somewhere. |
I think this is a duplicate of #1455. |
Thanks @EikeStein - can you please point us to the analyzer NuGet package and/or source code to help us root cause this? |
@mavasani This Analyzer should reproduce the issue: [DiagnosticAnalyzer(LanguageNames.CSharp)]
public class TestAnalyzer : DiagnosticAnalyzer
{
private static DiagnosticDescriptor TestRule { get; } = new DiagnosticDescriptor("Test001", "Method naming", "{0}", "Naming", DiagnosticSeverity.Error, true, "This diagnostic will not be shown");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(TestRule);
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.NamedType);
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method);
}
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
var symbol = context.Symbol;
if (symbol is IMethodSymbol methodSymbol)
{
const string forbiddenMethodName = "FaultyMethod";
if (methodSymbol.Name.Contains(forbiddenMethodName))
{
var diagnostic = Diagnostic.Create(TestRule, methodSymbol.Locations[0],
$"The method '{methodSymbol.Name}' contains forbidden content '{forbiddenMethodName}'\nConsider renaming your method");
context.ReportDiagnostic(diagnostic);
}
}
}
} The problematic part is the "\n" in the message. If I remove it everything works as expected. |
@EikeStein Awesome. @jcouv - does the compiler team have enough to investigate this issue further? I presume something in the command line compiler error reporting OR parsing is not handling multi-line diagnostic messages. We can either fix the command line compiler here OR detect this case in |
@mavasani Yes, I think we have enough information to proceed. I'm not sure where the issue is located though. The build from command-line did output the diagnostic, which makes it look like the analyzer and diagnostic handled the situation okay. |
@jcouv - I though @EikeStein initial screenshot shows |
Ah, okay. Probably a compiler issue then ;-) |
@jcouv Any updates on this? It is not super urgent, though. |
@EikeStein Sorry, no update yet. |
Analyzer package
Custom analyzer published to private NuGet feed. Works for any open files and with the setting "Enable full solution analysis" also for closed files, as long as the project is not build.
Repro steps
Expected behavior
The error from the analyzer should be reported in either the output window (especially for CI) or at least in the Error List window - preferable both. The error should not disappear after a build has failed.
Actual behavior
No information/reason for the failed build is given anywhere

The text was updated successfully, but these errors were encountered: