CA1703 CodeAnalysis Error and CasingExceptions - code-analysis

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?

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.

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

Related

RTI DDS creating own data types

I am working on a .Net example where I define my own data type using RTI Connext DDS.
Instead of creating the application from the beginning, I got help from the source code of the hello_world_xml_dynamic example in rti_workspace directory. I have made several changes to the USER_QOS_PROFILES.xml file to create my own data type and changes its name to MY_PROFILES.xml
But when I compile the application and run it from the command line, I get the following error:
DDS_DomainParticipantFactory_create_participant_from_config_w_paramsI:ERROR: Profile library 'MyParticipantLibrary::PublicationParticipant' not found
! Unable to create DDS domain participant
The line of code that catching the error:
if (this.participant == null)
{
this.participant = DDS.DomainParticipantFactory.get_instance().
create_participant_from_config(
"MyParticipantLibrary::PublicationParticipant");
if (this.participant == null)
{
Console.Error.WriteLine("! Unable to create DDS domain participant");
return;
}
}
this is the configuration file MY_PROFILES.xml :
<!--
RTI Data Distribution Service Deployment
-->
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/6.0.1/rti_dds_profiles.xsd">
<!-- Qos Library -->
<qos_library name="qosLibrary">
<qos_profile name="DefaultProfile">
</qos_profile>
</qos_library>
<!-- types -->
<types>
<struct name="FlightData">
<member name="Latitude" type="double"/>
<member name="Longitude" type="double"/>
<member name="Altitude" type="double"/>
</struct>
</types>
<!-- Domain Library -->
<domain_library name="MyDomainLibrary" >
<domain name="FlightDataDomain" domain_id="0">
<register_type name="FlightDataType"
type_ref="FlightData" />
<topic name="FlightDataTopic"
register_type_ref="FlightDataType">
<topic_qos name="FlightData_qos"
base_name="qosLibrary::DefaultProfile"/>
</topic>
</domain>
</domain_library>
<!-- Participant library -->
<domain_participant_library name="MyParticipantLibrary">
<domain_participant name="PublicationParticipant"
domain_ref="MyDomainLibrary::FlightDataDomain">
<publisher name="MyPublisher">
<data_writer name="FlightDataWriter"
topic_ref="FlightDataTopic"/>
</publisher>
</domain_participant>
<domain_participant name="SubscriptionParticipant"
domain_ref="MyDomainLibrary::FlightDataDomain">
<subscriber name="MySubscriber">
<data_reader name="FlightDataReader"
topic_ref="FlightDataTopic">
<datareader_qos name="FlightData_reader_qos"
base_name="qosLibrary::DefaultProfile"/>
</data_reader>
</subscriber>
</domain_participant>
</domain_participant_library>
</dds>
where am i making a mistake?
Your XML file looks correct. From the 'not found' error message, it seems that you may not have taken the right steps to instruct your application to load that profiles-file MY_PROFILES.xml to actually learn about your desired Participant. You can easily verify that this is the case by introducing an error in your XML file (for example by incorrectly renaming one tag) and rerun your application. If it does not complain about the syntax or schema of the XML, then your file did not get loaded and this hypothesis is correct.
If that turns out to be your problem indeed, then you have several options to fix that. They are listed in the User's Manual section 18.5 How to Load XML-Specified QoS Settings.

What does this web.xml error mean?

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
Referenced file contains errors (http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd). For more information, right click on the message in the Problems View and select "Show Details..."
The errors below were detected when validating the file "web-app_2_5.xsd" via the file "web.xml". In most cases these errors can be detected by validating "web-app_2_5.xsd" directly. However it is possible that errors will only occur when web-app_2_5.xsd is validated in the context of web.xml.
In details, I see a bunch of these:
s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than xs:appinfo and xs:documentation. Saw 'var _U="undefined";'
If you replace j2ee by javaee, it will work fine.
EDIT :
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Edit:
To know anything further related to this error. Please follow the Link. Here you will find schemas for Java EE deployment descriptors (web.xml).
replace
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
with
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee;http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
The solution is that you have to put semicolon between URLs
I am sure you will not get the error again :)
I suggest you add ; between 2 passages:
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee and http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Like this:
:xsi:schemaLocation="http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Add semicolon between xsi:schemaLocation just as shown below
"http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
This resolved my this error in <servlet-name> tag line as well.
"cvc-id.3: A field of identity constraint 'web-common-servlet-name-uniqueness' matched element 'web-app', but this element does not have a simple type."
In my case, I had replaced
xsi:schemaLocation="http://java.sun.com/../.."
with
xsi:schemaLocation="http://xmlns.jcp.org/../.."
Cheers!
On the surface it appears that the schemaLocation is wrong. Resolving it appears to redirect to a HTML page rather than a XSD schema.
I would suggest simply removing this line unless you really want to do XSD validation at runtime. Bear in mind the relevant parts will be validated by your servlet container.
Replacing the schemaLocation as below has resovled the error for me:
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/j2ee; http://xmlns.jcp.org/xml/ns/j2ee/web-app_2_4.xsd"

Rule CA1709 and two letter-words

I have a library with a lot of functions that use two letter-non english-words like this:
FinDeDia
EsPrimo
EnPreparacion
...
Anyway, I activated code analysys for the project, and I'm getting the CA1709 warning:
CA1709 : Microsoft.Naming :
Corrija el uso de mayúsculas y minúsculas en 'De' en el nombre del miembro '...' cambiándolo a 'DE'.
I added a code analysis dictionary as stated here but it doesn't ignore the warnings. Here is the structure of the dictionary.
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Recognized>
<Word>de</Word>
<Word>el</Word>
<Word>en</Word>
<Word>es</Word>
<Word>si</Word>
...
</Recognized>
</Words>
</Dictionary>
What else should i do for handling this warning Without supressing the message?.
thanks in advance
You need to add them as CasingExceptions aswell:
<Acronyms>
<CasingExceptions>
<Acronym>De</Acronym>
<Acronym>El</Acronym>
<Acronym>En</Acronym>
<Acronym>Es</Acronym>
<Acronym>Si</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
EDIT:
Just be aware of the fact that this is somewhat a misuse, since none of those words are acronyms. Maybe you'd rather want to disable those specific rules. Afterall, many of code analysis' rules are based on the assumption that the API is written in English.

XML configuration of Zend_Form: child nodes and attributes not always equal?

A set of forms (using Zend_Form) that I have been working on were causing me some headaches trying to figure out what was wrong with my XML configuration, as I kept getting unexpected HTML output for a particular INPUT element. It was supposed to be getting a default value, but nothing appeared.
It appears that the following 2 pieces of XML are not equal when used to instantiate Zend_Form:
Snippet #1:
<form>
<elements>
<test type="hidden">
<options ignore="true" value="foo"/>
</test>
</elements>
</form>
Snippet #2:
<form>
<elements>
<test type="hidden">
<options ignore="true">
<value>foo</value>
</options>
</test>
</elements>
</form>
The type of the element doesn't appear to make a difference, so it doesn't appear to be related to hidden fields.
Is this expected or not?
As it was rather quiet on here, I took a look further into the source code and documentation.
On line 259 of Zend_Config_Xml, the SimpleXMLElement object attributes are converted to a string, resulting in:
options Object of: SimpleXMLElement
#attributes Array [2]
label (string:7) I can't see this because
value (string:21) something happens to this
becoming
options (string:21) something happens to this
So, I hunted through the documentation only to find that "value" is a reserved keyword when used as an attribute in an XML file that is loaded into Zend_Config_Xml:
Example #2 Using Tag Attributes in Zend_Config_Xml
"..Zend_Config_Xml also supports two
additional ways of defining nodes in
the configuration. Both make use of
attributes. Since the extends and the
value attributes are reserved keywords
(the latter one by the second way of
using attributes), they may not be
used..."
Thus, it would appear to be "expected" according to the documentation.
I'm not entirely happy that this is a good idea though, considering "value" is an attribute of form elements.
Don't worry about this. The reserved keywords were moved to their own namespace, and the previous attributes were depricated. In Zend Framework 2.0 the non-namespaced attributes will be removed so you can use them again.

MSBuild XMLUpdate Question

I am using the XMLUpdate to update an xml formatted file in MSBuild. It updates fine but adds <?xml version="1.0" encoding="utf-8"?> at the top after update. Here is my statement that updates
<Import Project="C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<XmlUpdate XmlFileName="$(AppName).alx" Xpath="/loader/application/version" Value="$(AppVersion)" />
Is it possible to update without the xml element at the top?
Thanks
Ponnu
The <?xml ...> is more of a descriptor than a real XML element. It describes your document and, for example defines the encoding. It won't interfere with your existing elements. I think it is even a standard feature of a XML document (but I don't have the specs handy)