Case-sensitive code

Tweet

One situation I’ve witnessed numerous times is the fact that C# and the .NET platform is case-sensitive. This seems to cause problems for older Windows develoeprs that migrated from Visual Basic. One particular problem I encountered recently with an ASP.NET application was located in the Web.config file. The following line caused a problem with the application and the developer couldn’t figure out why:



Now, this is not invalid XML but it does conform to the design of the ASP.NET appSettings element. The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. Notice, the first letter of settings is capitalized, and the fact that it was not capitalized caused a problem. The server return the following error when the application was started:

Unrecognized configuration section ‘appsettings’

Now, it took me a few seconds to realize the problem but it illustrates the point that the .NET platform is largely case-sensitive unless you utlize VB.NET as your language (but the Web.config remains case-sensitive regardless of the language). The correct Web.config entry would be:



These issues exist in the C# and J# languages as well, but those can be caught during compilation.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Dangermouse

    Whats the point of case sensitivity in a config file? Or am i just being naive?

  • Jim

    XML is case-sensitive, so when the framework starts navigating through your config file (which is an XML file), it’s looking for elements that match exactly.

    “A” and “a” are actually two different entities so far as computers are concerned. They don’t differentiate between capital and lower-case unless it’s specified that there is an existing relationship between two characters (e.g. “A” and “a”).

    Since XML is case-sensitive, when the file is traversed, “” and “” are two completely different things.

    All of the above was an explanation of the simple answer to your question, Dangermouse: case-sensitivity in config files is not so much a necessity as much as it is a side effect of using XML for those files.

  • NeNe

    Web.config must be case sensitive because of XML specification (which says that tag and attribute names are case sensitive).

  • Jim

    Sorry, I didn’t mean “don’t differentiate between”, I meant “don’t make a connection between”, as it does differentiate.

  • http://www.rockymountainpc.com jlrosine

    I guess I’m just used to this. I don’t even notice that I’m typing in camel case and typing to conform anymore, it just comes with repetition.

    I have seen quite a few posts about it though, and it threw me for a loop when I was first starting with C#. Funny how long people could search for an error, whether it be as simple as a variable case not matching etc. Visual studio sure helps you figure out the problem before you get too far, which is nice.

  • http://www.dynamicfunctions.com Kadence

    What about spelling sensitivity? “develoeprs” :)

  • Mike in NH

    Funny but True (and sad) Story:
    I recently took a colleagues advice to start coding .net apps in c# (this after years of coding in vb). Started my first c# app. What, the heck!? What happened to Intellisense? It isn’t doing the Ini Caps thing. Then it dawns on me (here in NE we say, “light dawns on Marblehead”). Stomp over to my buddy’s cube. “What kind of development tool is this?? It makes me actually use the shift key??”

  • Anonymous

    i don’t understand how to enter a case-sensitive code

  • Anonymous

    tttt