Hi @Cindy See ,
The CS1061 error is caused when you try to call a method or access a class member that does not exist.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1061
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
- Make sure you typed the member name correctly.
- If you have access to modify this class, you can add the missing member and implement it.
- If you don't have access to modify this class, you can add an extension method.
When asking a question, you'd better provide a minimal reproducible example. so that we can better help you solve the problem.
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.