Case-Sensitivity in ASP.NET (VB)

Note to self, and anyone else who cares...

ViewState("ReferrerURL") is not the same as ViewState("ReferrerUrl").

Same with Cache object names.  Apparently VB does *kinda* care about case sensitivity...

 

5 Comments

  • VB only cares about case-sensitivity because the constructor for the Dictionary/Hashtable used for those is using the default comparer .. This can be overriden when you create your own dictionary collections.

    For all your VB code, you can also change the default comparison behaviour for string comparers at a project/file level, by changing the Option Compare from Binary (default) to Text.

    Not sure if this will affect the Viewstate/Cache objects though



  • Actually, both cases refer to classes in the framework, so it's not the language that's case sensitive, but rather the rules of the key/value collections for both Cache and ViewState.

  • Dave: Thanks.

    Jeff: Yeah. I've run into this before, but have just gotten lazy, I guess. Strange that as far as I know, key/value collections are NOT case sensitive for most other things (such as data objects, session variables, application variables, etc.) I wonder why they would be so specific (picky) about Cache and ViewState...

    Thanks for the feedback.

  • I think this is because the ViewState object, at the core, uses a HashTable to hold all of these key/pair values.

    (Using Reflector, you can trace back through this to verify...)

    So this exhibits the same behavior as a HashTable in VB.NET. Each key is a unique value, so it MUST be case-sensitive.

  • If you never talk directly to Viewstate and use a property instead, there is a much smaller chance of mistyping the name.

    Its the compiler that is case-insensitive, I really would be surprised to find out that "a" equals "A" ;)


Comments have been disabled for this content.