Export (0) Print
Expand All
Expand Minimize
0 out of 8 rated this helpful - Rate this topic

Compiler Error CS1061

'type' does not contain a definition for 'member' and no 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.

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

// cs1061.cs
public class TestClass1
{
    // TestClass1 has one method, called WriteSomething.
    public void WriteSomething(string s)
    {
        System.Console.WriteLine(s);
    }
}

public class TestClass2
{
    // TestClass2 has one method, called DisplaySomething.
    public void DisplaySomething(string s)
    {
        System.Console.WriteLine(s);
    }
}

public class TestTheClasses
{
    public static void Main()
    {
        TestClass1 tc1 = new TestClass1();
        TestClass2 tc2 = new TestClass2();
        // The following call fails because TestClass1 does not have 
        // a method called DisplaySomething.
        tc1.DisplaySomething("Hello");      // CS1061

        // To correct the error, change the method call to either 
        // tc1.WriteSomething or tc2.DisplaySomething.
        tc1.WriteSomething("Hello from TestClass1");
        tc2.DisplaySomething("Hello from TestClass2");
    }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.