CS0120
C# Programming Language
Severity: MinorWhat Does This Error Mean?
CS0120 means you tried to call a method or access a property that belongs to an instance of a class, but you called it from a static method without creating an object first. In other words: you tried to use a feature of a specific object without having that object. Think of it like trying to check the mileage of a car without referring to any particular car. The fix is either to create an object first, or to make the member static if it does not need an instance.
Affected Models
- .NET Framework
- .NET Core
- .NET 5+
- Visual Studio
- Visual Studio Code
- Rider
Common Causes
- Calling an instance method directly from the static Main() method without creating an object first
- Accessing instance fields or properties from within a static method in the same class
- Forgetting that the entry point (Main) is static, so all direct calls from it must use objects or static members
- Trying to call an event handler method (which is often non-static) from a static context
- Writing a utility method as a non-static member when it should be static
How to Fix It
-
Understand the error: you are inside a static method and you are trying to use something that belongs to a specific object, not to the class itself.
Static means 'belongs to the class'. Instance means 'belongs to a specific object created from that class'. You cannot use an instance member without an object.
-
Create an instance of the class first, then call the method or access the property through that instance.
Example: instead of calling MyMethod() from Main(), write: MyClass obj = new MyClass(); obj.MyMethod();
-
Alternatively, if the method does not need any object-specific data (it does not use 'this' or any instance fields), make it static.
Add the 'static' keyword to the method declaration: 'public static void MyMethod()' — then you can call it directly without an object.
-
Review which members of your class truly need to be instance members versus static. Pure utility functions, constants, and factory methods are good candidates for static.
Static members are shared by all instances. Instance members belong to each individual object. The choice depends on whether the member needs per-object data.
-
In ASP.NET or WinForms, if you are calling an event handler incorrectly, make sure the event subscription is set up through an object instance, not statically.
Event handlers in UI applications almost always need an object instance because they interact with specific form controls.
When to Call a Professional
CS0120 is a compile-time error you can always fix yourself. Understanding the difference between static and instance members resolves this error every time. For beginners, this is a very common early error — it means your understanding of object-oriented programming will click with practice.
Frequently Asked Questions
What is the difference between static and instance in C#?
A static member belongs to the class itself and is shared by everyone. An instance member belongs to a specific object created from the class. Example: 'Math.Sqrt()' is static — you call it on the Math class directly. 'myList.Count' is an instance member — it belongs to a specific list object. Static members exist even with no objects. Instance members only exist when an object exists.
When should I make a method static?
Make a method static when it does not use or modify any instance data (no 'this', no instance fields or properties). Good candidates: utility calculations, factory methods, validation helpers, conversion functions. If a method could work on its own without knowing about any specific object, it should probably be static. Static methods are also slightly faster because they do not need an object reference.
Why is Main() static in C#?
Main() is the entry point of a C# program — it runs before any objects exist. Because there are no objects yet when the program starts, Main() cannot be an instance method. Making it static means the runtime can call it without needing to create an object first. From Main(), you can create any objects you need and then call their instance methods.