C# Compiler Error
CS0146 – Circular base class dependency involving ‘class1’ and ‘class2’
Reason for the Error
You will receive this error when the C# compiler detects a circular dependency when inheriting from base class.
Take a look at the below code snippet
namespace DeveloperPublishNamespace { public class Class1 : DeveloperPublish { } public class DeveloperPublish : Class1 { public static void Main() { } } }
The Class1 inherits from DeveloperPublish. The class DeveloperPublish in turn inherits from Class1. This creates a circular base class dependency and results with the below error.
Error CS0146 Circular base type dependency involving ‘DeveloperPublish’ and ‘Class1’ ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 3 Active
Solution
A class in C# cannot inherit from itself. You will need to avoid inheriting from the base class that is causing circular base class dependency.