It was suggested that I raise this issue over here as well:
It appears that scanner for dotnet (5.0 and 5.2) seems to ignore:
#pragma warning disable
If we directly use the sq roslyn analyzers they show up a warning, we then use the vs2019 action: suppress in source, and vs2019 prefers to wrap the line with #pragma warning disable/enable:
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)); #pragma warning enable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
That appeases the roslyn analysis. However, when sonarscanner is used it seems to now ignore #pragma warning disable and the warning is shown in the msbuild binary log and on the SQ server.
[SuppressMessage("SonarQube", "S3011: Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design")]
does work, but has a broader scope, eg function or even class, not just on the one line, and also means converting things.
Is there a configuration setting I can change/investigate? I don’t know what exactly Scanner does, I suspect it’s pre-processing the .cs files, but the fact it causes csc to not process #pragma surprises me.