sexta-feira, 17 de agosto de 2007

CS0030: Cannot convert type

CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'

Another issue which I found really interesting... We had an ASP.NET 2.0 application and in one of the pages (called Login.aspx) we used the Login control. It worked beautifully from the IDE (F5 or CTRL+F5), but when we deployed it on the webserver (precompiled), it showed the following error.

Compiler Error Message: CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'

Source Error:
Line 112: public login_aspx() {
Line 113: string[] dependencies;
Line 114: ((Login)(this)).AppRelativeVirtualPath = "~/Login.aspx";
Line 115: if ((global::ASP.login_aspx.@__initialized == false)) {
Line 116: dependencies = new string[1];

Source File: c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filescpi.operations.field.assv32f5e4c75ac0558eApp_Web_login.aspx.cdcab7d2.crjut9bu.0.cs Line: 114

Clearly, it was looking like a name conflict. We changed the name of the page class from Login to Login1 and re-deployed on the webserver and it worked fine, as expected.

Moral of the story... in 2.0, don't use Login as a class name if you intend to use the Login Control. It is not really that big a compromise, specially if you consider the functionality of Login control!! Besides, you can always name your page as Login.aspx. All you need to ensure is that, the name of the class of that page is NOT called Login.

PS. It is not that naming a class as Login WILL run into problems, but just in case you get the above error and your symptoms match, I hope this might help you...