False Positive with IDE0370
Version Used: VS Insiders [11304.161]
Steps to Reproduce: Open testf solution.
A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into .NET Lab.
Diagnostic Id: IDE0370 Suppression is unecessary
Expected Behavior:
No IDE0370 on the snippet below because GetMethod returns nullable.
Actual Behavior:
public void HasCorrectClassOrAssemblyInitializeSignatureShouldReturnTrueForTestMethods()
{
MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("PublicStaticMethodWithTC")!; // IDE0370 here
methodInfo.HasCorrectClassOrAssemblyInitializeSignature().Should().BeTrue();
}
Looks like tehse are reporting in net462/net48, which is appropriate. Those suppressions are not necessary there.
Unfortunately, a fundamental restriction of analyzers is they run per-compilation. So they don't know about other 'flavors' that you are compiling for where the suppression may be necessary. The fixer does know though, and won't remove these if you do 'fix all in solution'.
Given htat you are targeting old runtimes, you probably just want to disable this analyzer.
In netfx, is it really correct that the compiler assumes it's non-nullable? I feel like when the nullability info are not present, compiler should always assume null. Am I missing something?
The analyzer is saying that the supression is not necessary and can eb safely removed. That is true in netfx. just as there is no nullability info, the suppression is also not needed.
Imagine if we didn't have this. someone might have a method with all sorts of unneccessary ! in there that they thought they needed. and they'd never know they coudl remove it.
maybe there is some wya to disable that analyzer jsut for that particular compilation flavor.
maybe there is some wya to disable that analyzer jsut for that particular compilation flavor.
I was going to ask if you know a trick. Because with .editorconfig I don't know how I can disable this for netfx only.
@jaredpar is there a way to disable analyzers or provide a specific editorconfig/options set to a particular analysis of one flavor of a project?
There is no way to toggle editorconfig based on TFM, at least that I'm aware of. When we've hit problems like this in the past we've just used the <NoWarn Condition="'$(TargetFramework)' == 'net472'>... approach
There is also no way to conditionally include .editorconfig files based on the TFM, right? Only globalconfig files can be included/excluded in that way, I think.
Can we combine ruleset and editorconfig? Maybe that could be a way.
Although the NoWarn is not bad.