Compiler Error CS1061

'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 extension method.

See also