The app does not contain a definition

I have a C # forms application. I am importing an additional CS file into the program and now it no longer compiles. Every time I try to compile, I get the following messages:

Application does not contain a definition for 'EnableVisualStyles' Application does not contain a definition for 'SetCompatibleTextrenderingDefault' Application does not contain a definition for 'Run' 

When I click on errors, they lead me to Programs.cs. It simply contains the following information:

 /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } 

Any help would be appreciated.

Another point: the test console application works fine, however I want this application to be a formal application.

+4
source share
2 answers

You have added a new using statement for a namespace that has a different Application definition (it may be your own) and takes precedence. You can use the full name to make sure you are targeting the correct Application class:

 global::System.Windows.Forms.Application.EnableVisualStyles(); global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); global::System.Windows.Forms.Application.Run(new Form1()); 

(You can omit global:: if you also don't have a class named System , but the above is just more convincing in the fact of ambiguous namespace / class namespace.

Other alternatives include renaming the custom Application class if it is really yours, rather than adding using for any namespace for this file (or any file that uses the System.Windows.Forms Application class) by adding an alias for System.Windows.Forms.Application (this is done with something like using FormApplication = System.Windows.Forms.Application; ) etc.

+8
source

I encountered this problem when using the Entity Model Framework to connect to a database that had a table named "Application". After the classes were created for the database, I immediately had two "Application" classes that caused the error. In my main () method, Program.cs, the following code changed the problem:

 System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.Run(new MyForm()); 
0
source

Source: https://habr.com/ru/post/1468828/


All Articles