EngageProgramEveryone knows that the naming of variables should not conflict with the language keywords. Today, I also encountered a problem caused by the naming of ASP. NET Web controls. This problem is easy to confuse people.
I created a page named "file. aspx" andCodeThe "file" class is used on the page. According to the general operation, first import the "system. io "namespace, the results in the Code body found that the file class does not have its common method, even if you manually write a correct File class operation code, it cannot be compiled, the method added after the file class is not included in the file class. The error code is as follows:
Using System;
Using System. Data;
Using System. configuration;
Using System. collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. IO;
Public Partial Class File: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
Streamreader SR = File. opentext (server. mappath ( " . " ) + " \ Table. SQL " );
}
}
You may have noticed the problem, that is, there are two file classes, one is system. io. file, the other is to automatically generate a class public partial class file with the same name as the file name when creating a web page. In this case, the file class definition in the Code body streamreader sr = file is ambiguous, in this case, the IDE automatically prompts that the member is under the public partial class file class, so the problem occurs at the beginning.
Knowing where the problem is, the solution will naturally be found. One solution is to always remind you not to duplicate the name of the created web page file with the class to be used in the Code. Another more scientific method is to use the namespace full name or namespace alias, as shown below:
Using System;
Using System. Data;
Using System. configuration;
Using System. collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. IO;
Public Partial Class File: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
Streamreader SR = System. Io. file. opentext (server. mappath ( " . " ) + " \ Table. SQL " );
}
}
This problem is obviously simple, but a little careless will make you think that there is a problem with the. NET Framework or vs IDE, it is worth noting!