HomeCSharpC# Error CS0146 – Circular base class dependency involving ‘class1’ and ‘class2’

C# Error CS0146 – Circular base class dependency involving ‘class1’ and ‘class2’

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.

C# Error CS0146 – Circular base class dependency involving 'class1' and 'class2'

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.

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...