C# Compiler Error
CS0243 – The Conditional attribute is not valid on ‘method’ because it is an override method
Reason for the Error
You will receive this error in your C# program when you have used the Conditional Attribute on a method that is marked as override.
For example, try compiling the below code snippet.
namespace DeveloperPubNamespace { public class BaseClass { public virtual void Method1() { } } public class ChildClass : BaseClass { [System.Diagnostics.ConditionalAttribute("DeveloperPub")] public override void Method1() { } } class Program { public static void Main() { } } }
This program will result with the C# error code CS0243 because the ConditionalAttribute on the Method1 that is marked as override in the ChildClass.
Error CS0243 The Conditional attribute is not valid on ‘ChildClass.Method1()’ because it is an override method DeveloperPublish C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 10 Active
Solution
The C# compiler will never bind the override methods. You can only bind the base method. Hence the ConditionalAttribute is not allowed on the override methods in C#.