How to resolve error CS1061?

Cindy See 206 Reputation points
2022-10-25T05:42:13.007+00:00

I have a data access layer and business object layer in my ASP.Net web application.
Everytime when I made changes to the existing function or added a new function in the data access layer and business object layer, it will throw error CS1061 when I build the solution. I think it is because the metadata of these files in the layer are locked and not reflecting the latest changes. How can I resolve or avoid this issue?

Developer technologies ASP.NET ASP.NET Core
Developer technologies Visual Studio Debugging
Developer technologies ASP.NET Other
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-10-25T06:22:31.633+00:00

    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

    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.

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.