C# Error CS0577 – The Conditional attribute is not valid on ‘{0}’ because it is a constructor, destructor, operator, lambda expression, or explicit interface implementation

C# Error

CS0577 – The Conditional attribute is not valid on ‘{0}’ because it is a constructor, destructor, operator, lambda expression, or explicit interface implementation

Reason for the Error & Solution

The Conditional attribute is not valid on ‘function’ because it is a constructor, destructor, operator, or explicit interface implementation

Conditional cannot be applied to the specified methods.

For example, you cannot use some attributes on an explicit interface definition. The following sample generates CS0577:

// CS0577.cs  
// compile with: /target:library  
interface I  
{  
   void m();  
}  
  
public class MyClass : I  
{  
   [System.Diagnostics.Conditional("a")]   // CS0577  
   void I.m() {}  
}  

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...