ClassName case sensitive

V

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ç
 
S

Sven Groot

Vicenç Masanas said:
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.

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top