Dirk Schiffner
Dirk Schiffner

Reputation: 123

CA1703 CodeAnalysis Error and CasingExceptions

I have a text resource "{0} by Test GmbH" which is correctly spelled because GmbH is the official Abbreviation for "Gesellschaft mit beschränkter Haftung". I understand that Microsoft CodeAnalysing tries to tokenize it into "Gmb" and "H" however I think it should be possible to introduce this term as known with that specific spelling and casing with this CodeAnalysingDictionary:

<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
  <Words>
    <Unrecognized>
    </Unrecognized>
    <Recognized>
      <Word>Gmbh</Word>
    </Recognized>
    <Deprecated>
    </Deprecated>
    <DiscreteExceptions>
      <Term>GmbH</Term>
    </DiscreteExceptions>
  </Words>
  <Acronyms>
    <CasingExceptions>
      <Acronym>GmbH</Acronym>
    </CasingExceptions>
  </Acronyms>
</Dictionary>

However it does not work out:

CA1703  Resource strings should be spelled correctly    
In resource 'MyCode.Properties.Resources.resx', 
referenced by name 'CopyrightWithCompanyName', 
correct the spelling of 'Gmb' in string value '{0} by Test GmbH'.   

How can I adjust the dictionary correctly?

Upvotes: 1

Views: 467

Answers (2)

DavidRR
DavidRR

Reputation: 19457

Actually, provided that GmbH should be interpreted as a compound word that consists of the words Gmb and H, the casing of GmbH is correct.

So, in order for GmbH to be seen as valid by Code Analysis and thereby eliminate CA1703, simply add gmb as a recognized word to your custom dictionary file:

<Dictionary>
  <Words>
    <Recognized>
      <Word>gmb</Word>
      <!-- ... -->
    </Recognized>
    <!-- ... -->
  </Words>
  <!-- ... -->
</Dictionary>

I confirmed that this works in Visual Studio 2013.

Upvotes: 1

Sebastian Roether
Sebastian Roether

Reputation: 451

According to http://msdn.microsoft.com/en-us/library/bb514188.aspx#bkmk_dictionaryacronymscasingexceptionsacronym entries in the CasingExceptions are only applied to CA1709: Identifiers should be cased correctly, not to resources.

I have the exact same problem but no solution other then suppress the warning

Upvotes: 0

Related Questions