I have a C# forms application. I import an additional CS file into the program and now it doesn't compile any more. Every time I try 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 the errors it bring me to Programs.cs. It just 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.
One more point, a test console app works fine, however I want this app to be forms application.
You added a new using
statement for a namespace that has another definition of Application
, (it might be your own) and that is taking precedence. You can use the fully qualified name to be sure that you're targeting the right 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 the global::
as long as you don't also have a class named System
but the above is just a tad more robust in the fact of ambiguous namespace/class names.
Other alternatives include renaming the custom Application
class, if it is indeed your own, not adding a using
for whatever namespace it's in for this file (or any file that uses the System.Windows.Forms
Application
class), adding an alias for System.Windows.Forms.Application
(this is done by something like using FormApplication = System.Windows.Forms.Application;
), etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With