C#
programming error
instance member
type error
coding issues

Instance member cannot be used on type

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

This C# error means you tried to access an instance property, field, or method through the class itself instead of through an object. In other words, the compiler sees you treating a type name as if it were an actual instance.

The fix is usually simple once you identify which side of the static-versus-instance boundary the member belongs to.

Instance Members Need an Object

An instance member belongs to a specific object:

csharp
1public class Car
2{
3    public string Make { get; set; } = "";
4
5    public void PrintMake()
6    {
7        Console.WriteLine(Make);
8    }
9}

This is wrong:

csharp
Car.PrintMake();

because Car is a type, not an object. The correct usage is:

csharp
var car = new Car { Make = "Toyota" };
car.PrintMake();

Now there is a real Car instance to operate on.

Static Members Belong to the Type

Static members are the opposite. They belong to the class itself:

csharp
1public class Car
2{
3    public static int WheelCount => 4;
4}
5
6Console.WriteLine(Car.WheelCount);

So a useful way to think about the error is:

  • instance members need an object
  • static members use the type name

If you cross those two ideas, the compiler complains.

A Common Real-World Case

This error often appears inside static methods such as Main:

csharp
1public class Program
2{
3    public string Message { get; set; } = "Hello";
4
5    public static void Main()
6    {
7        Console.WriteLine(Message);
8    }
9}

Main is static, so there is no implicit this. The code is trying to use the instance property Message without an instance of Program.

One fix is to create an object:

csharp
1public class Program
2{
3    public string Message { get; set; } = "Hello";
4
5    public static void Main()
6    {
7        var program = new Program();
8        Console.WriteLine(program.Message);
9    }
10}

Another fix is to make the member static if it truly belongs to the type rather than to a particular object.

How to Decide Between Static and Instance

Ask whether the data or behavior depends on object state.

If it depends on per-object values, keep it as an instance member:

csharp
1public class Counter
2{
3    public int Value { get; private set; }
4
5    public void Increment() => Value++;
6}

If it represents shared behavior with no instance state, static may be right:

csharp
1public static class MathHelpers
2{
3    public static int Square(int x) => x * x;
4}

Do not make something static merely to silence the compiler. That changes the design, not just the syntax.

Extension Methods and Similar Confusion

Developers sometimes hit this error while assuming a member is static because it "looks utility-like." Extension methods add to the confusion because they are declared as static methods but called like instance methods:

csharp
1public static class StringExtensions
2{
3    public static string Shout(this string value) => value.ToUpperInvariant();
4}
5
6Console.WriteLine("hello".Shout());

The call site looks instance-based, but the declaration is static. That is valid because extension methods are a special language feature.

Common Pitfalls

The biggest pitfall is changing a member to static just to make the error disappear. If the member depends on object state, that is the wrong fix.

Another common issue is referencing instance members from static contexts such as Main, static constructors, or static helper methods.

People also forget that properties are members too. The rule is not limited to methods; Type.Property is just as wrong when the property is instance-based.

Finally, if dependency injection or framework code is supposed to create the object for you, make sure you are using the injected instance rather than the class name.

Summary

  • The error means an instance member was accessed through a type name.
  • Instance members require an object reference.
  • Static members belong to the type and can be accessed through the class name.
  • In static methods, there is no implicit instance.
  • Fix the access pattern first, and only make a member static if that matches the actual design.

Course illustration
Course illustration