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

|
0 Comments:
Post a Comment
<< Home