C# Error CS1955 – Non-invocable member ‘{0}’ cannot be used like a method.

C# Error

CS1955 – Non-invocable member ‘{0}’ cannot be used like a method.

Reason for the Error & Solution

Non-invocable member ‘name’ cannot be used like a method.

Only methods and delegates can be invoked. This error is generated when you try to use empty parentheses to call something other than a method or delegate.

To correct this error

  1. Remove the parentheses from the expression.

Example

The following code generates CS1955 because the code is trying to invoke a field and a property by using the . You cannot call a field or a property. Use the to access the value it stores.

// cs1955.cs  
class A  
{  
    public int x = 0;  
    public int X  
    {  
        get { return x; }  
        set { x = value; }  
    }  
}  
  
class Test  
{  
    static int Main()  
    {  
        A a = new A();  
        a.x(); // CS1955  
        a.X(); // CS1955  
        // Try this line instead:  
        // int num = a.x;  
    }  
}  

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...