Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo
ClassName case sensitive (Saturday, September 18, 2004)
 

Found the following interesting discussion in the Newsgroups:

ClassName case sensitive
by:Vicenç Masanas

I had a problem with some webforms and user controls. From time to time when
developing a new form or user control and testing I got the following error:

Could not load type 'xml.WebForm1'

I use to fight with this for a while and I allways endend up deleting the
form and starting again. Then it worked.

BUT TODAY I FOUND MY PROBLEM!

This error was showing becase on the <@page> or <@control> directive I had
an Inherits clause that pointed to a class which was slightly misspelled:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="xml.WebForm1"%>

and in the code behind file I had:

Public Class webForm1
Inherits System.Web.UI.Page
....

Notice the difference in the initial character of the className: just a
lowercase or uppercase difference. I've found the same problem with user
controls.

I've tried with different projects and I get the same result on all. It's
quite easy to reproduce:

create a new web project (defaults with WebForm1.aspx)
compile and run
---> it works

change the inherits clause on the <@ page> directive (just upper or lower
case, for example to Webform1
compile and run
----> it doesn't work

Why? Please can someone give a reason of this behaviour?

Vicenç


 Reply:
by:Sven Groot

 
Name lookup in the .Net Framework is case sensitive. This is reflected in
languages such as C#, where 'somename', 'Somename', 'someName' are all
different entities. Although Visual Basic as a language is not case
sensitive, this is just the Visual Basic compiler abstracting away the case
sensitivity of the CLR. The VB compiler takes extra effort to produce IL
code where the names do match. So if you declare your class webForm1, but
reference it somewhere else as WebForm1, the IL the VB compiler will emit
will actually make that reference read webForm1 to have the case match.

Apparently, the @page directive in ASP.NET, which is after all used by all
languages, not just VB, does not have this feature. So lookup is case
dependant.

--
Sven Groot



Posted by Xander Zelders



 
Previous Posts
    - Tokenizer question
    - Adding buttons programmatically in visual basic .n...
    - convert function to IntPtr
    - Creating objects with New
    - Save record in datagrid while still editing
    - How to Get info from MDI child
    - About a datagrid row
    - How to Pass Parameters to an Event
    - How to delete all the contents in a datagrid
    - Build error for VB.NET but not C#

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland