HomeCSharpC# Error CS1061 – ‘{0}’ does not contain a definition for ‘{1}’ and no accessible extension method ‘{1}’ accepting a first argument of type ‘{0}’ could be found (are you missing a using directive or an assembly reference?)

C# Error CS1061 – ‘{0}’ does not contain a definition for ‘{1}’ and no accessible extension method ‘{1}’ accepting a first argument of type ‘{0}’ could be found (are you missing a using directive or an assembly reference?)

C# Error

CS1061 – ‘{0}’ does not contain a definition for ‘{1}’ and no accessible extension method ‘{1}’ accepting a first argument of type ‘{0}’ could be found (are you missing a using directive or an assembly reference?)

Reason for the Error & Solution

‘type’ does not contain a definition for ‘name’ and no accessible extension method ‘name’ accepting a first argument of type ‘type’ could be found (are you missing a using directive or an assembly reference?).

This error occurs when you try to call a method or access a class member that does not exist.

Example

The following example generates CS1061 because Person does not have a DisplayName method. It does have a method that is called WriteName. Perhaps that is what the author of this source code meant to write.

public class Person
{
    private string _name;

    public Person(string name) => _name = name;

    // Person has one method, called WriteName.
    public void WriteName()
    {
        System.Console.WriteLine(_name);
    }
}

public class Program
{
    public static void Main()
    {
        var p = new Person("PersonName");

        // The following call fails because Person does not have
        // a method called DisplayName.
        p.DisplayName(); // CS1061
    }
}

To correct this error

  1. Make sure you typed the member name correctly.
  2. If you have access to modify this class, you can add the missing member and implement it.
  3. If you don’t have access to modify this class, you can add an .

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...