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:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cpi.operations.field.assv\32f5e4c7\5ac0558e\App_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…


Cheers!
Rahul

Comments (27)

  1. Kotrim says:

    I had the same problem but this time because of the Calendar Control 🙂

    Great help :D, thanks

  2. xiko says:

    Maybe it could give us a warning ata build time…

  3. rahulso says:

    Basically, it is because of the change in compilation model in 2.0.

    http://msdn.microsoft.com/msdnmag/issues/06/01/ExtremeASPNET/

    Hope this helps!

  4. annie says:

    my page was named Login.aspx and gave the same error; i have chabged the name and now it works

  5. Davide says:

    Great help!

    I had this issue + the issue with a page named Error.aspx, I had to rename the inherited class to Error1 and it worked.

  6. DotNet Circle says:

    this link will throw light on this issue

    http://heybo.com/weblog/posts/524.aspx

  7. Andrew Sims says:

    Same problem, same solution – rename the class.

    How many times will I fall into this trap !!!!

  8. Madalina says:

    Thanks for the post 🙂

  9. AZU says:

    I had the same error with a page named menu.aspx so don´t use menu as page name

  10. I had the same problem with a page called View.aspx, so I guess that is also a name to avoid… It disappeared when I renamed to ViewSpecimen.aspx

  11. Andy says:

    Thanks Rahul

    I also found that changepassword.aspx has the same issue.

  12. Robert says:

    Thanks, Rahul! This really helped me out.

  13. George S. says:

    We had the same issue. Renaming of the class workded like charm. But what if you need to have class name that get in conflict? (in our case the class was named Content). This is where namespaces become handy!

    Cheers,

    George S.

  14. David Rogers says:

    We had this error. We cleared the problem up by examing the page directive in Login.aspx. We noticed that the Inherits="Login" had a specific reference to an assembly, as in Inherits="Login, blah-blah".  We deleted the ", blah-blah" and that fixed the problem.

  15. coki says:

    I have same problem, thank 4 u solution

  16. Gayathri says:

    Had the same problem.Solved now.Renamed the class and working. Thanks a lot.

  17. sandipon says:

    thanks for this artical , i was facing same problem for fileupload control , but now it sloved

  18. Atul Kapase says:

    Its same as name conflict, just change Page  Class ReportViewer to ReportViewer1

  19. Niteen Jadhav says:

    same problem using Login.aspx with class name Login. changed class name. it works.

    Thanks.

  20. Anders yu says:

    the "Login" is saved by c#, so change it.

  21. Tommy says:

    We renamed our class to _Login instead of Login1.

    I find the naming of … well anything… with a number suffix (like Login1, TextBox1, DropDownlist1, etc) simply silly. But VS needs to name it something else, but also you better believe I then rename it to something else 😉

    And yeah; the Login control does really save us a lot of work!

  22. You’ve been kicked (a good thing) – Trackback from DotNetKicks.com

  23. Alochan says:

    Just use namespace on each page of ur website

    namespace MyNamespace

    {

    public partial class Login

    {

    }

    }

    it will work

    Regards

    Alochan

  24. sangam says:

    Yeah, i got this problem while deploying my application in my localhost. The treatment I did is to add a namespace in the Login.aspx.cs file and update it from the Login.aspx’s Inherits property. Thank you.

  25. amiya says:

    every page has default class (pagename)  but how it become automatically login .

    Now How i chane it login to login1 it gives error

  26. Anuja says:

    Thanks Rahul…

    It worked for me toooo:)

  27. Kirtikumar says:

    I had the same error with a page named menu.aspx so don´t use menu as page name