CA1704 - Microsoft seems to be blocking the word &

2019-04-20 04:58发布

问题:

public class MultiSomething { } //CA1704:IdentifiersShouldBeSpelledCorrectly

When I run Code Analysis, I get an error because the Microsoft does not recognize the word 'Multi' (go figure they use it in IMultiValueConverter). So, what I did to correct this was to add a CodeAnalysisDictionary.xml file and followed the steps supplied here. However, it doesn't seem to solve the situation, I still get a Code Analysis warning message.

To ensure that this isn't a bug with the recognized words section, I added another class and another exception.

public class MultiSomething { } //CA1704:IdentifiersShouldBeSpelledCorrectly
public class MutiiSomething { } //NO WARNING

<Dictionary>
  <Words>
    <Recognized>
      <Word>Multi</Word> <-- This seems to not do anything... -->
      <Word>Mutii</Word> <-- This actually does something... -->
    </Recognized>
  </Words>
</Dictionary>

An alternative to fixing it is to use SuppressMessage, though that isn't a well fit solution if I plan on using this word all over the place.

[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi")]
public class MultiSomething { } //NO WARNING (Suppressed)

Did Microsoft actually block 'Multi' from being added to the recognized words?

回答1:

You can refer to this feedback ticket. This is apparently by design.

The behavior you are seeing is because Code Analysis ships with a pre-defined custom dictionary that always overrides any other custom dictionaries when there is a conflict. In this case “multi” is listed as an <unrecognized> word in the default FXCop dictionary.

To fix this issue, open the default dictionary %VS Install Directory%\Team Tools\Static Analysis Tools\FxCop\CustomDictionary.xml and comment out or remove the “multi” entry from the <unrecognized> words section; "multi" will no longer be flagged as a spelling error in Code Analysis.



回答2:

try adding this to your customdictionary

<Deprecated>
  <Term PreferredAlternate="Multi">multi</Term>
</Deprecated>