C# Error CS0582 – The ConditionalAttribute is not valid on an interface member

C# Compiler Error

CS0582 – The ConditionalAttribute is not valid on an interface member

Reason for the Error

You will get this error in your C# code when have used the conditional attribute on an interface member.

For example, let’s compile the below C# program

using System;
using System.Diagnostics;

namespace DeveloperPublishConsoleCore
{
    interface IEmployee
    {
        // CS0582  
        [ConditionalAttribute("ERROR")]  
        void GetEmployeeData();
    }

    internal class Program
    {      
        static void Main(string[] args)
        {
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

You will receive the error code CS0582 because you have an interface method GetEmployeeData and you have applied the ConditionalAttribute on it.

C# Error CS0582 – The ConditionalAttribute is not valid on an interface member

Error CS0582 The Conditional attribute is not valid on interface members DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 9 Active

Solution

C# doesn’t allow you to have a condtional attribute on an interface member.

You can fix this error in your C# program by either removing the conditional attribute from the interface member.

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