The suggested code fix depends on which target framework your IDE uses.
In Visual Studio, you can choose which target framework to use by selecting it in the left-most dropdown on top of your file:
In your case, you are probably using netstandard2.1; thus, the suggested code fix is for netstandard2.1.
This happens because, when doing the analysis, we get the information only about the currently used target framework, we do not know about any other targeted framework.
Similarly, the code fix for IDE0074 will suggest you to use a null-coalescing assignment even though you are also targeting net472.
To prevent the wrong code fix from being suggested, make sure to always set the current target framework to net472.
Today I hit another issue quite similar. So, I guess it is correct to update this thread instead of create a new one.
The rule S6513 “Add a justification” raises issues on ExcludeFromCodeCoverageAttribute. But, the Justification property is only available in newer dotnet versions. It is not available in .NET Framework 4.8.
My analysis reports:
Using the .NET Framework version of the Scanner for MSBuild
How can we achieve correct analysis in multi-targeting environment?
What is happening here is that since you are targeting two frameworks there will be two compilations (one for net48 and one for net8).
Each compilation will raise issues according to the framework and then the issues will be aggregated and that’s why you are actually seeing this issue raised (it comes from the net8 compilation, if your project would target only net48 the issue would not be there at all).
Making a choice when aggregating the issues based on the target frameworks is a pretty complex topic that we decided to not go into.
I have 2 suggestions as a workaround:
Either you could use preprocessor directives to compile that part only for net48.
Either deactivate this rule fully since for this project from my POV it has nothing to offer (every single issue will be an FP for net48).