C# Error CS0578 – The Conditional attribute is not valid on ‘{0}’ because its return type is not void

C# Error

CS0578 – The Conditional attribute is not valid on ‘{0}’ because its return type is not void

Reason for the Error & Solution

The Conditional attribute is not valid on ‘function’ because its return type is not void

cannot be applied to a method that has a return type other than void. The reason for this is that any other return type for a method may be needed by another part of your program.

Example

The following sample generates CS0578. To resolve this error, you must either delete , or you must change the return value of the method to void.

// CS0578.cs
// compile with: /target:library
public class MyClass
{
    [System.Diagnostics.ConditionalAttribute("a")]   // CS0578
    public int TestMethod()
    {
        return 0;
    }
}

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